Test "make sure to context-switch to idle thread when therad's status is PS_EXITED" on arm64

Change-Id: I757d529e49655e9010022f10414e4d6c9eb4c059
Refs: #1029
This commit is contained in:
Shiratori, Takehiro
2018-12-04 17:03:53 +09:00
committed by Masamichi Takagi
parent 01b2a1d213
commit 0ee446923a
13 changed files with 450 additions and 0 deletions

View File

@ -0,0 +1,73 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sched.h>
#define DEF_LOOPS 10
int main(int argc, char** argv) {
pid_t pid[256];
cpu_set_t cpu_set;
int result, i, j;
int loops = DEF_LOOPS;
if (argc > 1) {
loops = atoi(argv[1]);
}
CPU_ZERO(&cpu_set);
CPU_SET(1, &cpu_set);
result = sched_setaffinity(0, sizeof(cpu_set_t), &cpu_set);
if (result != 0) {
perror("Error sched_setaffinity()");
return(1);
}
for (i = 0; i < loops && (pid[i] = fork()) > 0; i++);
if (i == loops) { // parent
for (i = 0; i < loops; i++) {
waitpid(pid[i], NULL, 0);
}
}
else if (pid[i] == 0) {
cpu_set_t child_set;
CPU_ZERO(&child_set);
CPU_SET(2, &child_set);
result = sched_setaffinity(0, sizeof(cpu_set_t), &child_set);
if (result != 0) {
perror("Error sched_setaffinity() on child");
}
result = sched_yield();
if (result != 0) {
perror("Error sched_yield()");
}
CPU_ZERO(&child_set);
CPU_SET(1, &child_set);
result = sched_setaffinity(0, sizeof(cpu_set_t), &child_set);
if (result != 0) {
perror("Error sched_setaffinity() on child");
}
result = sched_yield();
if (result != 0) {
perror("Error sched_yield()");
}
printf("child[%d] is done.\n", i);
return(0);
}
else {
perror("Error fork()");
return(1);
}
printf("parent is done.\n");
return(0);
}