fix: pthread_setname_np tests to match compat behavior
[deliverable/lttng-ust.git] / tests / pthread_name / pthread_name.c
index 05298f5bbeff26409b55664441586370cfc1ce31..b6c7831b5720d0c8b4d8cd389736a1d5b055956f 100644 (file)
 int main()
 {
        int ret;
-       char name[TEST_NAME_PROPER_LEN];
+       char name1[TEST_NAME_PROPER_LEN];
+       char name2[TEST_NAME_PROPER_LEN];
+       char too_long_name[] = "thisnameistoolong";
        char short_name[] = "labatt50";
        char short_name_ust[] = "labatt50-ust";
-       char long_name[] = "thisnameistoolong";
-       char long_name_ust[] = "thisnameist-ust";
+       char long_name[] = "procrastinating";
+       char long_name_ust[] = "procrastina-ust";
 
-       plan_tests(9);
+       plan_tests(12);
 
-       ret = lttng_pthread_getname_np(name, TEST_NAME_PROPER_LEN);
-       ok(ret == 0, "Get the thread name: %s", name);
+       /* Get the initial thread name */
+       ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN);
+       ok(ret == 0, "Get the thread name: '%s'", name1);
+
+       /* Set a thread name of more than 16 bytes, should fail */
+       ret = lttng_pthread_setname_np(too_long_name);
+       ok(ret == ERANGE, "Set a too long thread name: '%s'", too_long_name);
+
+       /* Get the thread name again, shouldn't have changed */
+       ret = lttng_pthread_getname_np(name2, TEST_NAME_PROPER_LEN);
+       ok(ret == 0, "Get the thread name: '%s'", name2);
+       ok(strcmp(name1, name2) == 0, "Compare the initial thread name: '%s' == '%s'", name1, name2);
 
        /* Set a thread name of less than 16 bytes */
        ret = lttng_pthread_setname_np(short_name);
-       ok(ret == 0, "Set a short thread name: %s", short_name);
+       ok(ret == 0, "Set a short thread name: '%s'", short_name);
 
-       ret = lttng_pthread_getname_np(name, TEST_NAME_PROPER_LEN);
-       ok(ret == 0, "Get a short thread name: %s", name);
-       ok(strcmp(short_name, name) == 0, "Compare the short thread name: %s == %s", short_name, name);
+       /* Get the thread name again, should be the one we set */
+       ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN);
+       ok(ret == 0, "Get a short thread name: '%s'", name1);
+       ok(strcmp(short_name, name1) == 0, "Compare the short thread name: '%s' == '%s'", short_name, name1);
 
        /* Append "-ust" to the thread name */
        lttng_ust_setustprocname();
-       ret = lttng_pthread_getname_np(name, TEST_NAME_PROPER_LEN);
-       ok(strcmp(short_name_ust, name) == 0, "Compare the short UST thread name: %s == %s", short_name_ust, name);
+       ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN);
+       ok(strcmp(short_name_ust, name1) == 0, "Compare the short UST thread name: '%s' == '%s'", short_name_ust, name1);
 
 
-       /* Set a thread name of more than 16 bytes */
+       /* Set a thread name of 16 bytes */
        ret = lttng_pthread_setname_np(long_name);
-       ok(ret == 0, "Set a long thread name: %s", long_name);
+       ok(ret == 0, "Set a long thread name: '%s'", long_name);
 
-       ret = lttng_pthread_getname_np(name, TEST_NAME_PROPER_LEN);
-       ok(ret == 0, "Get a truncated long thread name: %s", name);
-       ok(strncmp(long_name, name, TEST_NAME_PROPER_LEN - 1) == 0, "Compare the truncated long thread name: %s == %s", long_name, name);
+       /* Get the thread name again, should be the one we set */
+       ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN);
+       ok(ret == 0, "Get a long thread name: '%s'", name1);
+       ok(strncmp(long_name, name1, TEST_NAME_PROPER_LEN - 1) == 0, "Compare the long thread name: '%s' == '%s'", long_name, name1);
 
        /* Append "-ust" to the thread name which will truncate its end */
        lttng_ust_setustprocname();
-       ret = lttng_pthread_getname_np(name, TEST_NAME_PROPER_LEN);
-       ok(strcmp(long_name_ust, name) == 0, "Compare the long UST thread name: %s == %s", long_name_ust, name);
+       ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN);
+       ok(strcmp(long_name_ust, name1) == 0, "Compare the long UST thread name: '%s' == '%s'", long_name_ust, name1);
 
        return exit_status();
 }
This page took 0.024941 seconds and 5 git commands to generate.