diff --git a/regression/apps/Makefile b/regression/apps/Makefile index 8a50147e..64b2ca47 100644 --- a/regression/apps/Makefile +++ b/regression/apps/Makefile @@ -8,7 +8,20 @@ CUR_DIR := $(patsubst %/,%,$(dir $(MKFILE_PATH))) INITRAMFS ?= $(CUR_DIR)/../build/initramfs REGRESSION_BUILD_DIR ?= $(INITRAMFS)/regression -TEST_APPS := signal_c pthread network hello_world hello_pie hello_c fork_c fork execve pty mongoose +# These test apps are sorted by name +TEST_APPS := \ + execve \ + fork \ + fork_c \ + getpid \ + hello_c \ + hello_pie \ + hello_world \ + mongoose \ + network \ + pthread \ + pty \ + signal_c \ C_SOURCES := $(shell find . -type f \( -name "*.c" -or -name "*.h" \) ) diff --git a/regression/apps/getpid/Makefile b/regression/apps/getpid/Makefile new file mode 100644 index 00000000..c603a781 --- /dev/null +++ b/regression/apps/getpid/Makefile @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: MPL-2.0 + +include ../test_common.mk + +EXTRA_C_FLAGS := diff --git a/regression/apps/getpid/getpid.c b/regression/apps/getpid/getpid.c new file mode 100644 index 00000000..af2191a6 --- /dev/null +++ b/regression/apps/getpid/getpid.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: MPL-2.0 + +#define _GNU_SOURCE +#include +#include +#include +#include + +#define NUM_OF_CALLS 1000000 + +int main() +{ + struct timespec start, end; + long seconds, nanoseconds, total_nanoseconds, avg_latency; + pid_t pid; + + clock_gettime(CLOCK_MONOTONIC, &start); + + for (int i = 0; i < NUM_OF_CALLS; i++) { + pid = syscall(SYS_getpid); + } + + clock_gettime(CLOCK_MONOTONIC, &end); + + seconds = end.tv_sec - start.tv_sec; + nanoseconds = end.tv_nsec - start.tv_nsec; + + total_nanoseconds = seconds * 1e9 + nanoseconds; + avg_latency = total_nanoseconds / NUM_OF_CALLS; + + printf("Process %d executed the getpid() syscall %d times.\n", pid, + NUM_OF_CALLS); + printf("Syscall average latency: %ld nanoseconds.\n", avg_latency); + + return 0; +} diff --git a/regression/apps/scripts/process.sh b/regression/apps/scripts/process.sh index 3b00757e..84087fa6 100755 --- a/regression/apps/scripts/process.sh +++ b/regression/apps/scripts/process.sh @@ -8,7 +8,7 @@ SCRIPT_DIR=/regression cd ${SCRIPT_DIR}/.. echo "Start process test......" -tests="hello_world/hello_world fork/fork execve/execve fork_c/fork signal_c/signal_test pthread/pthread_test hello_pie/hello pty/open_pty" +tests="hello_world/hello_world fork/fork execve/execve fork_c/fork signal_c/signal_test pthread/pthread_test hello_pie/hello pty/open_pty getpid/getpid" for testcase in ${tests} do echo "Running test ${testcase}......"