0001
0002
0003
0004 #include <test_progs.h>
0005 #include <time.h>
0006 #include "test_varlen.skel.h"
0007
0008 #define CHECK_VAL(got, exp) \
0009 CHECK((got) != (exp), "check", "got %ld != exp %ld\n", \
0010 (long)(got), (long)(exp))
0011
0012 void test_varlen(void)
0013 {
0014 int duration = 0, err;
0015 struct test_varlen* skel;
0016 struct test_varlen__bss *bss;
0017 struct test_varlen__data *data;
0018 const char str1[] = "Hello, ";
0019 const char str2[] = "World!";
0020 const char exp_str[] = "Hello, \0World!\0";
0021 const int size1 = sizeof(str1);
0022 const int size2 = sizeof(str2);
0023
0024 skel = test_varlen__open_and_load();
0025 if (CHECK(!skel, "skel_open", "failed to open skeleton\n"))
0026 return;
0027 bss = skel->bss;
0028 data = skel->data;
0029
0030 err = test_varlen__attach(skel);
0031 if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err))
0032 goto cleanup;
0033
0034 bss->test_pid = getpid();
0035
0036
0037 memcpy(bss->buf_in1, str1, size1);
0038 memcpy(bss->buf_in2, str2, size2);
0039 bss->capture = true;
0040 usleep(1);
0041 bss->capture = false;
0042
0043 CHECK_VAL(bss->payload1_len1, size1);
0044 CHECK_VAL(bss->payload1_len2, size2);
0045 CHECK_VAL(bss->total1, size1 + size2);
0046 CHECK(memcmp(bss->payload1, exp_str, size1 + size2), "content_check",
0047 "doesn't match!\n");
0048
0049 CHECK_VAL(data->payload2_len1, size1);
0050 CHECK_VAL(data->payload2_len2, size2);
0051 CHECK_VAL(data->total2, size1 + size2);
0052 CHECK(memcmp(data->payload2, exp_str, size1 + size2), "content_check",
0053 "doesn't match!\n");
0054
0055 CHECK_VAL(data->payload3_len1, size1);
0056 CHECK_VAL(data->payload3_len2, size2);
0057 CHECK_VAL(data->total3, size1 + size2);
0058 CHECK(memcmp(data->payload3, exp_str, size1 + size2), "content_check",
0059 "doesn't match!\n");
0060
0061 CHECK_VAL(data->payload4_len1, size1);
0062 CHECK_VAL(data->payload4_len2, size2);
0063 CHECK_VAL(data->total4, size1 + size2);
0064 CHECK(memcmp(data->payload4, exp_str, size1 + size2), "content_check",
0065 "doesn't match!\n");
0066 cleanup:
0067 test_varlen__destroy(skel);
0068 }