Skip to content

Commit

Permalink
test: add extra debugging information to the icmp tests
Browse files Browse the repository at this point in the history
Signed-off-by: समीर सिंह Sameer Singh <lumarzeli30@gmail.com>
  • Loading branch information
ss141309 committed Jan 9, 2025
1 parent f873c3c commit 2f3d141
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/zdtm/lib/sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,32 @@ int sysctl_write_int(const char *name, int val)
return ret;
}

int sysctl_read_str(const char *name, char *data, int data_len)
{
int fd;
int ret;

fd = open(name, O_RDONLY);
if (fd < 0) {
pr_perror("Can't open %s", name);
return fd;
}

ret = read(fd, data, data_len - 1);
if (ret < 0) {
pr_perror("Can't read %s", name);
ret = -errno;
goto err;
}

data[ret] = '\0';

ret = 0;
err:
close(fd);
return ret;
}

int sysctl_write_str(const char *name, const char *val)
{
int fd;
Expand Down
1 change: 1 addition & 0 deletions test/zdtm/lib/sysctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

extern int sysctl_read_int(const char *name, int *data);
extern int sysctl_write_int(const char *name, int val);
extern int sysctl_read_str(const char *name, char *data, int data_len);
extern int sysctl_write_str(const char *name, const char *val);

#endif
9 changes: 9 additions & 0 deletions test/zdtm/static/socket6_icmp.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "zdtmtst.h"
#include "sysctl.h"

const char *test_doc = "static test for IP6/ICMP socket\n";
const char *test_author = "समीर सिंह Sameer Singh <lumarzeli30@gmail.com>\n";
Expand All @@ -20,6 +21,8 @@ const char *test_author = "समीर सिंह Sameer Singh <lumarzeli30@g
#define PACKET_SIZE 64
#define RECV_TIMEOUT 1

#define PING_GROUP_RANGE "/proc/sys/net/ipv4/ping_group_range"

static int echo_id = 1234;

int main(int argc, char **argv)
Expand All @@ -36,6 +39,12 @@ int main(int argc, char **argv)

sock = socket(PF_INET6, SOCK_DGRAM, IPPROTO_ICMPV6);
if (sock < 0) {
char buf[16];
gid_t current_gid = getgid();
sysctl_read_str(PING_GROUP_RANGE, buf, 16);

pr_perror("current GID: %d", current_gid);
pr_perror("net.ipv4.ping_group_range: %s", buf);
pr_perror("Can't create socket");
return 1;
}
Expand Down
9 changes: 9 additions & 0 deletions test/zdtm/static/socket_icmp.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "zdtmtst.h"
#include "sysctl.h"

const char *test_doc = "static test for ICMP socket\n";
const char *test_author = "समीर सिंह Sameer Singh <lumarzeli30@gmail.com>\n";
Expand All @@ -20,6 +21,8 @@ const char *test_author = "समीर सिंह Sameer Singh <lumarzeli30@g
#define PACKET_SIZE 64
#define RECV_TIMEOUT 1

#define PING_GROUP_RANGE "/proc/sys/net/ipv4/ping_group_range"

static int echo_id = 1234;

int main(int argc, char **argv)
Expand All @@ -36,6 +39,12 @@ int main(int argc, char **argv)

sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_ICMP);
if (sock < 0) {
char buf[16];
gid_t current_gid = getgid();
sysctl_read_str(PING_GROUP_RANGE, buf, 16);

pr_perror("current GID: %d", current_gid);
pr_perror("net.ipv4.ping_group_range: %s", buf);
pr_perror("Can't create socket");
return 1;
}
Expand Down

0 comments on commit 2f3d141

Please sign in to comment.