Skip to content

Commit

Permalink
Add valgrind test for cat
Browse files Browse the repository at this point in the history
Signed-off-by: Ronnie Sahlberg <[email protected]>
  • Loading branch information
sahlberg committed Oct 25, 2024
1 parent 7a569c6 commit af5e622
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
6 changes: 6 additions & 0 deletions lib/libsmb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,12 @@ disconnect_cb_1(struct smb2_context *smb2, int status,
struct disconnect_data *dc_data = private_data;
struct smb2_pdu *pdu;

if (status != SMB2_STATUS_SUCCESS) {
smb2_set_nterror(smb2, status, "%s", nterror_to_str(status));
dc_data->cb(smb2, -ENOMEM, NULL, dc_data->cb_data);
free(dc_data);
return;
}
pdu = smb2_cmd_logoff_async(smb2, disconnect_cb_2, dc_data);
if (pdu == NULL) {
dc_data->cb(smb2, -ENOMEM, NULL, dc_data->cb_data);
Expand Down
32 changes: 20 additions & 12 deletions tests/prog_cat.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct pollfd {
int poll(struct pollfd *fds, unsigned int nfds, int timo);
#endif

int is_finished;
int is_finished = 0;
uint8_t buf[256 * 1024];
uint32_t pos;

Expand Down Expand Up @@ -72,13 +72,14 @@ void pr_cb(struct smb2_context *smb2, int status,
if (status < 0) {
printf("failed to read file (%s) %s\n",
strerror(-status), smb2_get_error(smb2));
exit(10);
is_finished = 1;
return;
}

if (status == 0) {
if (smb2_close_async(smb2, fh, cl_cb, NULL) < 0) {
printf("Failed to call smb2_close_async()\n");
exit(10);
is_finished = 1;
}
return;
}
Expand All @@ -88,7 +89,8 @@ void pr_cb(struct smb2_context *smb2, int status,
pos += status;
if (smb2_pread_async(smb2, fh, buf, 102400, pos, pr_cb, fh) < 0) {
printf("Failed to call smb2_pread_async()\n");
exit(10);
is_finished = 1;
return;
}
}

Expand All @@ -100,12 +102,14 @@ void of_cb(struct smb2_context *smb2, int status,
if (status) {
printf("failed to open file (%s) %s\n",
strerror(-status), smb2_get_error(smb2));
exit(10);
is_finished = 1;
return;
}

if (smb2_pread_async(smb2, fh, buf, 102400, 0, pr_cb, fh) < 0) {
printf("Failed to call smb2_pread_async()\n");
exit(10);
is_finished = 1;
return;
}
}

Expand All @@ -115,13 +119,15 @@ void cf_cb(struct smb2_context *smb2, int status,
if (status) {
printf("failed to connect share (%s) %s\n",
strerror(-status), smb2_get_error(smb2));
exit(10);
is_finished = 1;
return;
}

if (smb2_open_async(smb2, private_data, O_RDONLY,
of_cb, NULL) < 0) {
printf("Failed to call smb2_open_async()\n");
exit(10);
is_finished = 1;
return;
}
}

Expand All @@ -130,6 +136,7 @@ int main(int argc, char *argv[])
struct smb2_context *smb2;
struct smb2_url *url;
struct pollfd pfd;
int rc = 0;

if (argc < 2) {
usage();
Expand All @@ -152,7 +159,7 @@ int main(int argc, char *argv[])
if (smb2_connect_share_async(smb2, url->server, url->share, url->user,
cf_cb, (void *)url->path) != 0) {
printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2));
exit(10);
goto finished;
}

while (!is_finished) {
Expand All @@ -161,20 +168,21 @@ int main(int argc, char *argv[])

if (poll(&pfd, 1, 1000) < 0) {
printf("Poll failed");
exit(10);
goto finished;
}
if (pfd.revents == 0) {
continue;
}
if (smb2_service(smb2, pfd.revents) < 0) {
printf("smb2_service failed with : %s\n",
smb2_get_error(smb2));
break;
goto finished;
}
}

finished:
smb2_destroy_url(url);
smb2_destroy_context(smb2);

return 0;
return rc;
}
19 changes: 19 additions & 0 deletions tests/test_0302_cat_valgrind_socket_error.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

. ./functions.sh

echo "basic cat test with valgrind and session errors"

# This test depends on the file CAT existing on the share used for testing
# TODO: should create the file first

NUM_CALLS=`libtool --mode=execute strace ./prog_cat "${TESTURL}/CAT" 2>&1 >/dev/null | grep readv |wc -l`

for IDX in `seq 1 $NUM_CALLS`; do
echo -n "Testing prog_cat on root of share with socket failure at #${IDX} ..."
READV_CLOSE=${IDX} LD_PRELOAD=./ld_sockerr.so libtool --mode=execute valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./prog_cat "${TESTURL}/CAT" >/dev/null 2>valgrind.out || failure

success
done

exit 0

0 comments on commit af5e622

Please sign in to comment.