0001
0002 #include <test_progs.h>
0003 #include "test_probe_read_user_str.skel.h"
0004
0005 static const char str1[] = "mestring";
0006 static const char str2[] = "mestringalittlebigger";
0007 static const char str3[] = "mestringblubblubblubblubblub";
0008
0009 static int test_one_str(struct test_probe_read_user_str *skel, const char *str,
0010 size_t len)
0011 {
0012 int err, duration = 0;
0013 char buf[256];
0014
0015
0016 memset(buf, 1, sizeof(buf));
0017 memcpy(buf, str, len);
0018
0019
0020 skel->bss->user_ptr = buf;
0021
0022
0023 usleep(1);
0024
0025
0026 if (CHECK(skel->bss->ret < 0, "prog_ret", "prog returned: %ld\n",
0027 skel->bss->ret))
0028 return 1;
0029
0030
0031 err = memcmp(skel->bss->buf, str, len);
0032 if (CHECK(err, "memcmp", "prog copied wrong string"))
0033 return 1;
0034
0035
0036 memset(buf, 0, sizeof(buf));
0037 err = memcmp(skel->bss->buf + len, buf, sizeof(buf) - len);
0038 if (CHECK(err, "memcmp", "trailing bytes were not stripped"))
0039 return 1;
0040
0041 return 0;
0042 }
0043
0044 void test_probe_read_user_str(void)
0045 {
0046 struct test_probe_read_user_str *skel;
0047 int err, duration = 0;
0048
0049 skel = test_probe_read_user_str__open_and_load();
0050 if (CHECK(!skel, "test_probe_read_user_str__open_and_load",
0051 "skeleton open and load failed\n"))
0052 return;
0053
0054
0055 skel->bss->pid = getpid();
0056
0057 err = test_probe_read_user_str__attach(skel);
0058 if (CHECK(err, "test_probe_read_user_str__attach",
0059 "skeleton attach failed: %d\n", err))
0060 goto out;
0061
0062 if (test_one_str(skel, str1, sizeof(str1)))
0063 goto out;
0064 if (test_one_str(skel, str2, sizeof(str2)))
0065 goto out;
0066 if (test_one_str(skel, str3, sizeof(str3)))
0067 goto out;
0068
0069 out:
0070 test_probe_read_user_str__destroy(skel);
0071 }