uti: integrate libuti and redirect to mck/libuti.so
Change-Id: I74e0f677ea8e1cd06e8ab05d92f1d38f9be8fd7a
This commit is contained in:
142
test/uti/libuti/src/uti_pthread_create01.c
Normal file
142
test/uti/libuti/src/uti_pthread_create01.c
Normal file
@@ -0,0 +1,142 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/mman.h>
|
||||
#include <signal.h>
|
||||
#include <uti.h>
|
||||
|
||||
pthread_mutex_t mutex1;
|
||||
pthread_cond_t cond1;
|
||||
pthread_mutex_t mutex2;
|
||||
pthread_cond_t cond2;
|
||||
char *m;
|
||||
int flag1, flag2;
|
||||
|
||||
int sigst;
|
||||
pthread_t thr;
|
||||
|
||||
void
|
||||
sigsegv(int s)
|
||||
{
|
||||
if (sigst == 1) {
|
||||
fprintf(stderr, "CT01007 munmap OK (SIGSEGV)\n");
|
||||
pthread_join(thr, NULL);
|
||||
fprintf(stderr, "CT01008 exit(pthread_join) OK\n");
|
||||
fprintf(stderr, "CT01009 futex (pthread_mutex/pthread_cond) OK\n");
|
||||
fprintf(stderr, "CT01010 END\n");
|
||||
exit(0);
|
||||
}
|
||||
printf("BAD SIGSEGV\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void *
|
||||
util_thread(void *arg)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = syscall(732);
|
||||
if (rc == -1)
|
||||
fprintf(stderr, "CT01003 running on Linux OK\n");
|
||||
else {
|
||||
fprintf(stderr, "CT01003 running on McKernel NG\n");
|
||||
exit(1);
|
||||
}
|
||||
errno = 0;
|
||||
m = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
|
||||
if (m != (void *)-1) {
|
||||
fprintf(stderr, "CT01004 mmap OK\n");
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "CT01004 mmap NG errno=%d\n", errno);
|
||||
exit(1);
|
||||
}
|
||||
strcpy(m, "mmap OK");
|
||||
pthread_mutex_lock(&mutex1);
|
||||
flag1 = 1;
|
||||
pthread_cond_signal(&cond1);
|
||||
pthread_mutex_unlock(&mutex1);
|
||||
|
||||
pthread_mutex_lock(&mutex2);
|
||||
while (!flag2) {
|
||||
pthread_cond_wait(&cond2, &mutex2);
|
||||
}
|
||||
flag2 = 0;
|
||||
pthread_mutex_unlock(&mutex2);
|
||||
rc = munmap(m, 4096);
|
||||
if (rc == 0) {
|
||||
fprintf(stderr, "CT01006 munmap OK\n");
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "CT01006 munmap NG errno=%d\n", errno);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&mutex1);
|
||||
flag1 = 1;
|
||||
pthread_cond_signal(&cond1);
|
||||
pthread_mutex_unlock(&mutex1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int rc;
|
||||
uti_attr_t uti_attr;
|
||||
|
||||
signal(SIGSEGV, sigsegv);
|
||||
pthread_mutex_init(&mutex1, NULL);
|
||||
pthread_cond_init(&cond1, NULL);
|
||||
pthread_mutex_init(&mutex2, NULL);
|
||||
pthread_cond_init(&cond2, NULL);
|
||||
|
||||
fprintf(stderr, "CT01001 mmap/munmap/futex/exit START\n");
|
||||
|
||||
if ((rc = uti_attr_init(&uti_attr))) {
|
||||
fprintf(stderr, "%s: error: uti_attr_init failed with %d\n",
|
||||
__func__, rc);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
rc = uti_pthread_create(&thr, NULL, util_thread, NULL, &uti_attr);
|
||||
if (rc) {
|
||||
fprintf(stderr, "%s: uti_pthread_create failed with %d\n",
|
||||
__func__, rc);
|
||||
exit(1);
|
||||
}
|
||||
fprintf(stderr, "CT01002 uti_pthread_create OK\n");
|
||||
pthread_mutex_lock(&mutex1);
|
||||
while (!flag1) {
|
||||
pthread_cond_wait(&cond1, &mutex1);
|
||||
}
|
||||
flag1 = 0;
|
||||
pthread_mutex_unlock(&mutex1);
|
||||
|
||||
fprintf(stderr, "CT01005 %s\n", m);
|
||||
pthread_mutex_lock(&mutex2);
|
||||
flag2 = 1;
|
||||
pthread_cond_signal(&cond2);
|
||||
pthread_mutex_unlock(&mutex2);
|
||||
|
||||
pthread_mutex_lock(&mutex1);
|
||||
while (!flag1) {
|
||||
pthread_cond_wait(&cond1, &mutex1);
|
||||
}
|
||||
flag1 = 0;
|
||||
pthread_mutex_unlock(&mutex1);
|
||||
|
||||
sigst = 1;
|
||||
fprintf(stderr, "%s\n", m);
|
||||
fprintf(stderr, "CT01007 munmap NG\n");
|
||||
pthread_join(thr, NULL);
|
||||
fprintf(stderr, "CT01008 exit(pthread_join) OK\n");
|
||||
fprintf(stderr, "CT01009 futex (pthread_mutex/pthread_cond) OK\n");
|
||||
fprintf(stderr, "CT01010 END\n");
|
||||
exit(0);
|
||||
}
|
||||
21
test/uti/libuti/src/uti_pthread_create01.sh.in
Normal file
21
test/uti/libuti/src/uti_pthread_create01.sh.in
Normal file
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# define WORKDIR
|
||||
SCRIPT_PATH=$(readlink -m "${BASH_SOURCE[0]}")
|
||||
SCRIPT_NAME="${SCRIPT_PATH##*/}"
|
||||
TEST_NAME="${SCRIPT_NAME%.sh}"
|
||||
AUTOTEST_HOME="${SCRIPT_PATH%/*/*/*}"
|
||||
if [ -f ${AUTOTEST_HOME}/bin/config.sh ]; then
|
||||
. ${AUTOTEST_HOME}/bin/config.sh
|
||||
else
|
||||
WORKDIR=$(pwd)
|
||||
fi
|
||||
|
||||
@WITH_MCK@/sbin/mcstop+release.sh
|
||||
@WITH_MCK@/sbin/mcreboot.sh @BOOTPARAM@
|
||||
|
||||
@WITH_MCK@/bin/mcexec --enable-uti @CMAKE_INSTALL_PREFIX@/bin/uti_pthread_create01 || exit $?
|
||||
|
||||
@WITH_MCK@/sbin/mcstop+release.sh
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user