uti: integrate libuti and redirect to mck/libuti.so

Change-Id: I74e0f677ea8e1cd06e8ab05d92f1d38f9be8fd7a
This commit is contained in:
Masamichi Takagi
2021-02-22 12:11:57 +09:00
parent 0848b64c1d
commit 82056961cd
10 changed files with 356 additions and 15 deletions

View File

@ -0,0 +1,102 @@
cmake_minimum_required(VERSION 3.0)
cmake_policy(SET CMP0005 NEW)
project(uti_libuti C)
execute_process(COMMAND bash -c "gawk '/CPU implementer/ { print \$4; exit; }' /proc/cpuinfo"
OUTPUT_VARIABLE CPU_IMPLEMENTER OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND bash -c "gawk '/CPU architecture/ { print \$3; exit; }' /proc/cpuinfo"
OUTPUT_VARIABLE CPU_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND bash -c "gawk '/CPU variant/ { print \$4; exit; }' /proc/cpuinfo"
OUTPUT_VARIABLE CPU_VARIANT OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND bash -c "gawk '/CPU part/ { print \$4; exit; }' /proc/cpuinfo"
OUTPUT_VARIABLE CPU_PART OUTPUT_STRIP_TRAILING_WHITESPACE)
if(CPU_IMPLEMENTER STREQUAL "0x46" AND CPU_ARCH STREQUAL "8" AND
CPU_VARIANT STREQUAL "0x1" AND CPU_PART STREQUAL "0x001")
message("A64FX detected")
set(CPU_MODEL "a64fx")
add_definitions(-D__a64fx__)
endif()
# Options: -DWITH_MCK=<McKernel install directory>
add_definitions(-DWITH_MCK=${WITH_MCK})
# libuti install directory
execute_process(COMMAND bash -c "grep -E '^LIBUTI_DIR' $ENV{HOME}/.mck_test_config | cut -d= -f2"
OUTPUT_VARIABLE LIBUTI_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
message("LIBUTI_DIR: ${LIBUTI_DIR}")
execute_process(COMMAND bash -c "grep -E '^BOOTPARAM' $ENV{HOME}/.mck_test_config | cut -d= -f2"
OUTPUT_VARIABLE BOOTPARAM OUTPUT_STRIP_TRAILING_WHITESPACE)
message("BOOTPARAM: ${BOOTPARAM}")
# for autotest
if(NOT DEFINED CMAKE_INSTALL_PREFIX_SCRIPTS)
set(CMAKE_INSTALL_PREFIX_SCRIPTS ${CMAKE_INSTALL_PREFIX}/scripts)
endif()
# CPPFLAGS
set(UNAME_R ${CMAKE_SYSTEM_VERSION} CACHE STRING "Kernel version to build against")
set(KERNEL_DIR "/lib/modules/${UNAME_R}/build" CACHE STRING "kernel build directory")
execute_process(COMMAND awk -F= "$1 == \"CONFIG_ARM64_64K_PAGES\" { print $2; exit; }" "${KERNEL_DIR}/.config"
OUTPUT_VARIABLE CONFIG_ARM64_64K_PAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
if(CONFIG_ARM64_64K_PAGES STREQUAL "y")
set(PAGE_SIZE "65536")
else()
set(PAGE_SIZE "4096")
endif()
else()
set(PAGE_SIZE "4096")
endif()
message("PAGE_SIZE: ${PAGE_SIZE}")
# CFLAGS
set(CFLAGS_WARNING "-Wall" "-Wextra" "-Wno-unused-parameter" "-Wno-sign-compare" "-Wno-unused-function" ${EXTRA_WARNINGS} CACHE STRING "Warning flags")
add_compile_options(
-O2
-g
${CFLAGS_WARNING}
)
# -L, this must be done before adding dependants
link_directories("${LIBUTI_DIR}/lib")
# -Wl,--rpath=, this must be done before adding dependants
# set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# set(CMAKE_INSTALL_RPATH "${WITH_MCK}/lib64/mck")
# test driver scripts
foreach(target IN ITEMS
uti_pthread_create01
)
# String replacement
configure_file(src/${target}.sh.in uti-${target} @ONLY)
# Install scripts
install(PROGRAMS ${CMAKE_BINARY_DIR}/uti-${target} DESTINATION ${CMAKE_INSTALL_PREFIX_SCRIPTS})
endforeach()
# programs running on Linux
foreach(target IN ITEMS
uti_pthread_create01
)
# Add C target
add_executable(${target} src/${target}.c)
# -I
target_include_directories(${target}
PRIVATE ${LIBUTI_DIR}/include
)
# -l
target_link_libraries(${target} PRIVATE pthread uti)
# Install
install(TARGETS ${target} DESTINATION bin)
endforeach()

21
test/uti/libuti/README Normal file
View File

@ -0,0 +1,21 @@
What to test
============
uti_pthread_created of <mckernel>/lib64/mck/libuti.so is called regardless of RPATH or LD_LIBRARY_PATH.
How to run
==========
cd ..
cwd=$(pwd)
&& rm -rf build && mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=$cwd/install -DWITH_MCK=$mcktest/work/mck ../libuti/
$cwd/install/scripts/uti-uti_pthread_create01
You should prepare $HOME/.mck_test_config. The example:
MCK_DIR=/home/m-takagi/project/os/install
BIN=/home/m-takagi/project/os/install/bin
SBIN=/home/m-takagi/project/os/install/sbin
BOOTPARAM="-c 12-59 -m 4G@0,4G@1,4G@2,4G@3 -r 12-35:0+36-59:1 -O"
LTP=/home/m-takagi/mcktest/ltp/install
LIBUTI_DIR=/home/m-takagi/libuti_linux

View 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);
}

View 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