On Tue, Nov 10, 2020 at 11:12 PM Andrey Konovalov <andreyk...@google.com> wrote: > > From: Vincenzo Frascino <vincenzo.frasc...@arm.com> > > This test is specific to MTE and verifies that the GCR_EL1 register > is context switched correctly. > > It spawn 1024 processes and each process spawns 5 threads. Each thread
Nit: "spawns" > + srand(time(NULL) ^ (pid << 16) ^ (tid << 16)); > + > + prctl_tag_mask = rand() % 0xffff; Nit: if you want values between 0 and 0xffff you probably want to use bitwise AND. > + > +int execute_test(pid_t pid) > +{ > + pthread_t thread_id[MAX_THREADS]; > + int thread_data[MAX_THREADS]; > + > + for (int i = 0; i < MAX_THREADS; i++) > + pthread_create(&thread_id[i], NULL, > + execute_thread, (void *)&pid); It might be simpler to call getpid() in execute_thread() instead. > +int mte_gcr_fork_test() > +{ > + pid_t pid[NUM_ITERATIONS]; > + int results[NUM_ITERATIONS]; > + pid_t cpid; > + int res; > + > + for (int i = 0; i < NUM_ITERATIONS; i++) { > + pid[i] = fork(); > + > + if (pid[i] == 0) { pid[i] isn't used anywhere else. Did you want to keep the pids to ensure that all children finished the work? If not, we can probably go with a scalar here. > + for (int i = 0; i < NUM_ITERATIONS; i++) { > + wait(&res); > + > + if(WIFEXITED(res)) > + results[i] = WEXITSTATUS(res); > + else > + --i; Won't we get stuck in this loop if fork() returns -1 for one of the processes? > + } > + > + for (int i = 0; i < NUM_ITERATIONS; i++) > + if (results[i] == KSFT_FAIL) > + return KSFT_FAIL; > + > + return KSFT_PASS; > +} > + -- Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Straße, 33 80636 München Geschäftsführer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg