Fix the pthread_setname_np test.
Fix the pthread_setname_np test to take into account that emulator kernels are so old that they don't support setting the name of other threads. The CLONE_DETACHED thread is obsolete since 2.5 kernels. Rename kernel_id to tid. Fix the signature of __pthread_clone. Clean up the clone and pthread_setname_np implementations slightly. Change-Id: I16c2ff8845b67530544bbda9aa6618058603066d
This commit is contained in:
@@ -187,7 +187,7 @@ TEST(pthread, pthread_sigmask) {
|
||||
}
|
||||
|
||||
#if __BIONIC__
|
||||
extern "C" int __pthread_clone(int (*fn)(void*), void* child_stack, int flags, void* arg);
|
||||
extern "C" int __pthread_clone(void* (*fn)(void*), void* child_stack, int flags, void* arg);
|
||||
TEST(pthread, __pthread_clone) {
|
||||
uintptr_t fake_child_stack[16];
|
||||
errno = 0;
|
||||
@@ -210,9 +210,20 @@ TEST(pthread, pthread_setname_np__self) {
|
||||
|
||||
#if __BIONIC__ // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
|
||||
TEST(pthread, pthread_setname_np__other) {
|
||||
pthread_t t1;
|
||||
ASSERT_EQ(0, pthread_create(&t1, NULL, SleepFn, reinterpret_cast<void*>(5)));
|
||||
ASSERT_EQ(0, pthread_setname_np(t1, "short 2"));
|
||||
// Emulator kernels don't currently support setting the name of other threads.
|
||||
char* filename = NULL;
|
||||
asprintf(&filename, "/proc/self/task/%d/comm", gettid());
|
||||
struct stat sb;
|
||||
bool has_comm = (stat(filename, &sb) != -1);
|
||||
free(filename);
|
||||
|
||||
if (has_comm) {
|
||||
pthread_t t1;
|
||||
ASSERT_EQ(0, pthread_create(&t1, NULL, SleepFn, reinterpret_cast<void*>(5)));
|
||||
ASSERT_EQ(0, pthread_setname_np(t1, "short 2"));
|
||||
} else {
|
||||
fprintf(stderr, "skipping test: this kernel doesn't have /proc/self/task/tid/comm files!\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user