Skip to content

Commit

Permalink
tetragon: Add more thread to TestExitLeader test
Browse files Browse the repository at this point in the history
Adding extra threads to the exit-leader test prog.

Spawning 2 threads directly from leader and another 2
from the newly created threads.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
  • Loading branch information
olsajiri committed May 23, 2023
1 parent 200c337 commit bb3b292
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
28 changes: 26 additions & 2 deletions contrib/tester-progs/exit-leader.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,29 @@
#include <stdlib.h>
#include <sys/syscall.h>

#define gettid() (int) syscall(SYS_gettid)

static void *worker(void *ctx)
{
int cnt = 3;
unsigned long cnt = (unsigned long) ctx;
pthread_t th;
int err;

fprintf(stderr, "worker %d:%d cnt %lu\n", getpid(), gettid(), cnt);

if (cnt == 2 || cnt == 4) {
err = pthread_create(&th, NULL, worker, (void *) (cnt + 1));
if (err) {
perror("pthread_create");
return NULL;
}
}

while (cnt--) {
sleep(1);
}

fprintf(stderr, "exit %d:%d\n", getpid(), gettid());
return NULL;
}

Expand All @@ -20,10 +36,18 @@ int main(void)
pthread_t th;
int err;

err = pthread_create(&th, NULL, worker, NULL);
err = pthread_create(&th, NULL, worker, (void *) 2);
if (err) {
perror("pthread_create");
return -1;
}
err = pthread_create(&th, NULL, worker, (void *) 4);
if (err) {
perror("pthread_create");
return -1;
}

sleep(3);
fprintf(stderr, "exit %d:%d\n", getpid(), gettid());
syscall(SYS_exit, 0);
}
4 changes: 2 additions & 2 deletions pkg/sensors/exec/exit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ func TestExitLeader(t *testing.T) {
fmt.Printf("exitTime %v\n", exitTime)
fmt.Printf("delta %v\n", delta)

if delta < 3*time.Second {
return fmt.Errorf("unexpected delta < 3 seconds")
if delta < 5*time.Second {
return fmt.Errorf("unexpected delta < 5 seconds")
}
return nil
}
Expand Down

0 comments on commit bb3b292

Please sign in to comment.