Skip to content

userspace: reduce CI userspace testing to tests that use it and fix some network tests #15230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/net/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ int zsock_setsockopt(int sock, int level, int optname,
* if :option:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* @endrststar
*/
int zsock_gethostname(char *buf, size_t len);
__syscall int zsock_gethostname(char *buf, size_t len);

/**
* @brief Convert network address from internal to numeric ASCII form
Expand Down
6 changes: 6 additions & 0 deletions kernel/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ k_tid_t z_impl_k_thread_create(struct k_thread *new_thread,
{
__ASSERT(!z_is_in_isr(), "Threads may not be created in ISRs");

/* Special case, only for unit tests */
#if defined(CONFIG_TEST) && defined(CONFIG_ARCH_HAS_USERSPACE) && !defined(CONFIG_USERSPACE)
__ASSERT((options & K_USER) == 0,
"Platform is capable of user mode, and test thread created with K_USER option, but CONFIG_TEST_USERSPACE or CONFIG_USERSPACE is not set\n");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be cleaner to just make it a general assertion if the caller asks for K_USER but the kernel can't accommodate? Or do we document that as a valid noop? Seems like there's nothing really test-specific about this validation other than the reason it was added.

Copy link
Contributor Author

@andrewboie andrewboie Apr 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For general usage, it's valid to disable userspace and still use things like K_USER or other related APIs. They are no-ops.

However, just for tests, we want to tighten this up as if someone is dropping a test to user mode in a test case, but forgets to set CONFIG_TEST_USERSPACE, it will not silently just run everything in supervisor mode.

We could consider making this a general assertion, but I am hesitant to do this here because we are so close to release. Re-visit for 1.15?

#endif

z_setup_new_thread(new_thread, stack, stack_size, entry, p1, p2, p3,
prio, options, NULL);

Expand Down
3 changes: 0 additions & 3 deletions samples/net/gptp/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,3 @@ tests:
sample.net.gptp:
platform_whitelist: frdm_k64f sam_e70_xplained native_posix
depends_on: netif
# To avoid "Too many thread objects" error
extra_configs:
- CONFIG_USERSPACE=n
11 changes: 10 additions & 1 deletion subsys/net/lib/sockets/sockets_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@

#include <errno.h>
#include <net/socket.h>
#include <syscall_handler.h>

int zsock_gethostname(char *buf, size_t len)
int z_impl_zsock_gethostname(char *buf, size_t len)
{
const char *p = net_hostname_get();

strncpy(buf, p, len);

return 0;
}

#ifdef CONFIG_USERSPACE
Z_SYSCALL_HANDLER(zsock_gethostname, buf, len)
{
Z_OOPS(Z_SYSCALL_MEMORY_WRITE(buf, len));
return z_impl_zsock_gethostname((char *)buf, len);
}
#endif
26 changes: 22 additions & 4 deletions subsys/testsuite/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,33 @@ config COVERAGE_GCOV
endif

config TEST_USERSPACE
bool "Enable userspace if available"
bool "Indicate that this test exercises user mode"
help
This option indicates that a test case puts threads in user mode,
and that the build system should enable userspace if the platform
supports it. It should be set on a per-test basis.

The userspace APIs are no-ops if userspace is not enabled, so it is
OK to enable this even if the test will run on platforms which do
not support userspace. The test should still run on those platforms,
just with all threads in supervisor mode.

If a test *requires* that userspace be enabled in order to
function, CONFIG_ARCH_HAS_USERSPACE should be filtered in its
testcase.yaml.

config TEST_ENABLE_USERSPACE
bool
depends on TEST_USERSPACE
depends on ARCH_HAS_USERSPACE
depends on TEST
select USERSPACE
select DYNAMIC_OBJECTS
default y
help
This option will help test the userspace mode. This can be enabled
only when CONFIG_ARCH_HAS_USERSPACE is set.
This hidden option will help test the userspace mode. This will be
enabled only when CONFIG_ARCH_HAS_USERSPACE is set, and that the test
case itself indicates that it exercises user mode via
CONFIG_TEST_HAS_USERSPACE.

config TEST_HW_STACK_PROTECTION
bool "Enable hardware-based stack overflow detection if available"
Expand Down
1 change: 0 additions & 1 deletion tests/benchmarks/app_kernel/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ CONFIG_MAIN_THREAD_PRIORITY=6
CONFIG_FORCE_NO_ASSERT=y

#Disable Userspace
CONFIG_TEST_USERSPACE=n
CONFIG_TEST_HW_STACK_PROTECTION=n
1 change: 0 additions & 1 deletion tests/benchmarks/app_kernel/prj_fp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ CONFIG_TICKLESS_KERNEL=n
CONFIG_FORCE_NO_ASSERT=y

#Disable Userspace
CONFIG_TEST_USERSPACE=n
CONFIG_TEST_HW_STACK_PROTECTION=n
3 changes: 0 additions & 3 deletions tests/benchmarks/boot_time/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@ CONFIG_PERFORMANCE_METRICS=y
CONFIG_BOOT_TIME_MEASUREMENT=y
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_FORCE_NO_ASSERT=y

#Disable Userspace
CONFIG_TEST_USERSPACE=n
CONFIG_TEST_HW_STACK_PROTECTION=n
2 changes: 0 additions & 2 deletions tests/benchmarks/latency_measure/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@ CONFIG_BT=n
#CONFIG_THREAD_MONITOR=y
CONFIG_FORCE_NO_ASSERT=y

#Disable Userspace
CONFIG_TEST_USERSPACE=n
CONFIG_TEST_HW_STACK_PROTECTION=n
CONFIG_COVERAGE=n
3 changes: 0 additions & 3 deletions tests/benchmarks/latency_measure/prj_small_freq_divider.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,4 @@ CONFIG_SYS_CLOCK_TICKS_PER_SEC=10
CONFIG_IRQ_OFFLOAD=y
CONFIG_FORCE_NO_ASSERT=y

#Disable Userspace
CONFIG_TEST_USERSPACE=n
CONFIG_TEST_HW_STACK_PROTECTION=n
CONFIG_COVERAGE=n
1 change: 0 additions & 1 deletion tests/benchmarks/sched/prj.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
CONFIG_TEST_USERSPACE=n
CONFIG_NUM_PREEMPT_PRIORITIES=8
CONFIG_NUM_COOP_PRIORITIES=8

Expand Down
2 changes: 0 additions & 2 deletions tests/benchmarks/sys_kernel/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ CONFIG_TICKLESS_KERNEL=n
CONFIG_MAIN_STACK_SIZE=16384
CONFIG_FORCE_NO_ASSERT=y

#Disable Userspace
CONFIG_TEST_USERSPACE=n
CONFIG_TEST_HW_STACK_PROTECTION=n
5 changes: 0 additions & 5 deletions tests/benchmarks/timing_info/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,5 @@ CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_HEAP_MEM_POOL_SIZE=256
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_FORCE_NO_ASSERT=y
CONFIG_APPLICATION_DEFINED_SYSCALL=y

#Disable Userspace
CONFIG_TEST_USERSPACE=n
CONFIG_TEST_HW_STACK_PROTECTION=n

CONFIG_SMP=n
1 change: 1 addition & 0 deletions tests/benchmarks/timing_info/prj_userspace.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ CONFIG_HEAP_MEM_POOL_SIZE=256
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_FORCE_NO_ASSERT=y
CONFIG_APPLICATION_DEFINED_SYSCALL=y
CONFIG_TEST_USERSPACE=y
2 changes: 0 additions & 2 deletions tests/bluetooth/init/prj_controller_dbg.conf
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,3 @@ CONFIG_DEBUG=y
CONFIG_FLASH=y
CONFIG_SOC_FLASH_NRF_RADIO_SYNC=n
CONFIG_ZTEST=y
# FIXME see #7704
CONFIG_TEST_USERSPACE=n
2 changes: 0 additions & 2 deletions tests/bluetooth/init/prj_controller_dbg_ll_sw_split.conf
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,3 @@ CONFIG_DEBUG=y
CONFIG_FLASH=y
CONFIG_SOC_FLASH_NRF_RADIO_SYNC=n
CONFIG_ZTEST=y
# FIXME see #7704
CONFIG_TEST_USERSPACE=n
2 changes: 0 additions & 2 deletions tests/bluetooth/mesh_shell/prj.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
CONFIG_TEST=y
#CONFIG_INIT_STACKS=y
CONFIG_TEST_USERSPACE=n
CONFIG_USERSPACE=n
CONFIG_MAIN_STACK_SIZE=448
CONFIG_ISR_STACK_SIZE=1024
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
Expand Down
1 change: 0 additions & 1 deletion tests/bluetooth/shell/mesh.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
CONFIG_TEST=y
CONFIG_USERSPACE=n
#CONFIG_INIT_STACKS=y
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

Expand Down
3 changes: 3 additions & 0 deletions tests/bluetooth/tester/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ CONFIG_BT_TESTING=y

CONFIG_UART_CONSOLE=n
CONFIG_GPIO=y

# FIXME: #15232
CONFIG_TEST_USERSPACE=y
1 change: 1 addition & 0 deletions tests/crypto/mbedtls/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ CONFIG_MBEDTLS_BUILTIN=y
CONFIG_MBEDTLS_CFG_FILE="config-tls-generic.h"
CONFIG_MBEDTLS_TEST=y
CONFIG_ZTEST=y
CONFIG_TEST_USERSPACE=y
2 changes: 1 addition & 1 deletion tests/crypto/mbedtls/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ tests:
platform_exclude: qemu_x86_64 # FIXME
min_flash: 65
min_ram: 32
tags: crypto mbedtls
tags: crypto mbedtls userspace
timeout: 200
1 change: 0 additions & 1 deletion tests/crypto/tinycrypt_hmac_prng/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ CONFIG_TINYCRYPT_SHA256=y
CONFIG_TINYCRYPT_SHA256_HMAC=y
CONFIG_TINYCRYPT_SHA256_HMAC_PRNG=y
CONFIG_ZTEST=y
CONFIG_TEST_USERSPACE=n
1 change: 1 addition & 0 deletions tests/drivers/adc/adc_api/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ CONFIG_LOG=y
CONFIG_ADC_LOG_LEVEL_INF=y
CONFIG_LOG_IMMEDIATE=y
CONFIG_HEAP_MEM_POOL_SIZE=1024
CONFIG_TEST_USERSPACE=y
2 changes: 1 addition & 1 deletion tests/drivers/adc/adc_api/testcase.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
common:
tags: peripheral adc
tags: peripheral adc userspace
tests:
peripheral.adc:
depends_on: adc
1 change: 1 addition & 0 deletions tests/drivers/build_all/drivers.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ CONFIG_SERIAL=y
CONFIG_SPI=y
CONFIG_WATCHDOG=y
CONFIG_X86_KERNEL_OOPS=n
CONFIG_TEST_USERSPACE=y
1 change: 1 addition & 0 deletions tests/drivers/build_all/ethernet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CONFIG_NETWORKING=y
CONFIG_NET_L2_ETHERNET=y
CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_TEST_USERSPACE=y

# No board will enable the generic SPI hosted enc28j60 driver by
# default, force it on:
Expand Down
2 changes: 1 addition & 1 deletion tests/drivers/build_all/gpio.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CONFIG_TEST=y
CONFIG_GPIO=y

CONFIG_TEST_USERSPACE=y
CONFIG_I2C=y
CONFIG_GPIO_SX1509B=y
1 change: 1 addition & 0 deletions tests/drivers/build_all/prj.conf
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
CONFIG_TEST=y
CONFIG_TEST_USERSPACE=y
1 change: 1 addition & 0 deletions tests/drivers/build_all/sensors_a_h.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CONFIG_SENSOR=y
CONFIG_SPI=y
CONFIG_LOG=y
CONFIG_SENSOR_LOG_LEVEL_DBG=y
CONFIG_TEST_USERSPACE=y

# Some sensor drivers (notably HP206C) demand high tick rates:
CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000
Expand Down
1 change: 1 addition & 0 deletions tests/drivers/build_all/sensors_i_z.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CONFIG_TEST=y
CONFIG_TEST_USERSPACE=y
CONFIG_GPIO=y
CONFIG_I2C=y
CONFIG_SENSOR=y
Expand Down
1 change: 1 addition & 0 deletions tests/drivers/build_all/sensors_trigger_a_h.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CONFIG_TEST=y
CONFIG_TEST_USERSPACE=y
CONFIG_I2C=y
CONFIG_ADC=y
CONFIG_GPIO=y
Expand Down
1 change: 1 addition & 0 deletions tests/drivers/build_all/sensors_trigger_i_z.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CONFIG_TEST=y
CONFIG_TEST_USERSPACE=y
CONFIG_I2C=y
CONFIG_ADC=y
CONFIG_GPIO=y
Expand Down
3 changes: 0 additions & 3 deletions tests/drivers/build_all/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ tests:
platform_exclude: frdm_kw41z
tags: drivers footprint
depends_on: adc spi
# FIXME see #7703
extra_configs:
- CONFIG_TEST_USERSPACE=n
test_build_sensors_i_z:
build_only: true
extra_args: CONF_FILE=sensors_i_z.conf
Expand Down
1 change: 1 addition & 0 deletions tests/drivers/i2s/i2s_api/prj.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
CONFIG_I2S=y
CONFIG_ZTEST=y
CONFIG_TEST_USERSPACE=y
2 changes: 1 addition & 1 deletion tests/drivers/i2s/i2s_api/testcase.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests:
peripheral.i2s:
depends_on: i2s
tags: drivers
tags: drivers userspace
2 changes: 1 addition & 1 deletion tests/kernel/common/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ CONFIG_POLL=y
CONFIG_QEMU_TICKLESS_WORKAROUND=y
CONFIG_BOOT_DELAY=500
CONFIG_IRQ_OFFLOAD=y

CONFIG_TEST_USERSPACE=y
CONFIG_SMP=n
2 changes: 1 addition & 1 deletion tests/kernel/common/testcase.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tests:
kernel.common:
tags: kernel
tags: kernel userspace
min_flash: 33
min_ram: 32
kernel.common.misra:
Expand Down
2 changes: 1 addition & 1 deletion tests/kernel/fatal/prj.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CONFIG_HW_STACK_PROTECTION=y
CONFIG_ZTEST=y
CONFIG_COVERAGE=n

CONFIG_TEST_USERSPACE=y
CONFIG_SMP=n
1 change: 0 additions & 1 deletion tests/kernel/fatal/sentinel.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
CONFIG_STACK_SENTINEL=y
CONFIG_TEST_HW_STACK_PROTECTION=n
CONFIG_TEST_USERSPACE=n
CONFIG_ZTEST=y
CONFIG_COVERAGE=n
CONFIG_SMP=n
Expand Down
4 changes: 2 additions & 2 deletions tests/kernel/fatal/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tests:
kernel.common.stack_protection:
extra_args: CONF_FILE=prj.conf
filter: CONFIG_ARCH_HAS_STACK_PROTECTION
tags: kernel ignore_faults
tags: kernel ignore_faults userspace
kernel.common.stack_sentinel:
extra_args: CONF_FILE=sentinel.conf
tags: kernel ignore_faults
tags: kernel ignore_faults userspace
1 change: 1 addition & 0 deletions tests/kernel/mem_protect/stackprot/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_MAIN_THREAD_PRIORITY=7
CONFIG_MAIN_STACK_SIZE=640
CONFIG_TEST_USERSPACE=y
2 changes: 1 addition & 1 deletion tests/kernel/mem_protect/stackprot/testcase.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests:
kernel.memory_protection:
arch_exclude: nios2 xtensa posix x86_64
tags: kernel ignore_faults
tags: kernel ignore_faults userspace
1 change: 1 addition & 0 deletions tests/kernel/mem_protect/userspace/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ CONFIG_ZTEST=y
CONFIG_INIT_STACKS=y
CONFIG_APPLICATION_DEFINED_SYSCALL=y
CONFIG_THREAD_USERSPACE_LOCAL_DATA=y
CONFIG_TEST_USERSPACE=y
4 changes: 1 addition & 3 deletions tests/kernel/msgq/msgq_api/prj.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
CONFIG_ZTEST=y
CONFIG_IRQ_OFFLOAD=y
CONFIG_USERSPACE=y
CONFIG_DYNAMIC_OBJECTS=y

CONFIG_TEST_USERSPACE=y
CONFIG_SMP=n
2 changes: 1 addition & 1 deletion tests/kernel/mutex/sys_mutex/prj.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CONFIG_MAIN_THREAD_PRIORITY=10
CONFIG_ZTEST=y
CONFIG_ZTEST_STACKSIZE=512

CONFIG_TEST_USERSPACE=y
CONFIG_SMP=n
1 change: 0 additions & 1 deletion tests/kernel/pipe/pipe/prj.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
CONFIG_ZTEST=y
CONFIG_TEST_USERSPACE=y

CONFIG_SMP=n
1 change: 0 additions & 1 deletion tests/kernel/pipe/pipe_api/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ CONFIG_ZTEST=y
CONFIG_IRQ_OFFLOAD=y
CONFIG_TEST_USERSPACE=y
CONFIG_DYNAMIC_OBJECTS=y

CONFIG_SMP=n
2 changes: 1 addition & 1 deletion tests/kernel/poll/prj.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CONFIG_ZTEST=y
CONFIG_POLL=y
CONFIG_DYNAMIC_OBJECTS=y

CONFIG_TEST_USERSPACE=y
CONFIG_SMP=n
Loading