Skip to content
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

tests/cmsis_rtos_v1 - test_mutex_lock_timeout results in Assertion failure on all targets with PR#9569 #9574

Closed
pswarnak opened this issue Aug 23, 2018 · 1 comment

Comments

Projects
None yet
3 participants
@pswarnak
Copy link
Contributor

commented Aug 23, 2018

The test tests/cmsis_rtos_v1 results in Assertion failure in test_mutex_lock_timeout sub-test case.

The changes are mainly related to mutex ownership test. It validates the below statement:
Only thread that obtains a mutex can release it

Arch: any or qemu_x86
Board: any or qemu_x86
Zephyr PR with code changes: #9569
Toolchain: ZEPHYR_TOOLCHAIN_VARIANT=zephyr
Shippable failure Link: https://app.shippable.com/github/zephyrproject-rtos/zephyr/runs/21146/1/tests

Code snippet to reproduce the error:

#define TIMEOUT 500

osMutexDef(Mutex_ownership);

void tThread_entry_mutex_ownership(void const *arg)
{
	osStatus status;

	/* Try to release mutex, obtained by another thread
	 * Only thread that obtains a mutex can release it
	 */
	status = osMutexRelease((osMutexId)arg);
	zassert_true(status == osErrorResource, "Mutex unexpectedly released");
}

osThreadDef(tThread_entry_mutex_ownership, osPriorityNormal, 1, 0);

void test_mutex_ownership(void)
{
	osThreadId id;
	osMutexId mutex_id;
	osStatus status;

	mutex_id = osMutexCreate(osMutex(Mutex_ownership));
	zassert_true(mutex_id != NULL, "Mutex2 creation failed");

	id = osThreadCreate(osThread(tThread_entry_mutex_ownership), mutex_id);
	zassert_true(id != NULL, "Thread creation failed");

	status = osMutexWait(mutex_id, osWaitForever);
	zassert_true(status == osOK, "Mutex wait failure");

	/* wait for spawn thread to take action */
	osDelay(TIMEOUT);

	/* Release the mutex */
	osMutexRelease(mutex_id);

	osMutexDelete(mutex_id);
}

Error Console Log:

***** Booting Zephyr OS v1.13.0-rc1-4-gf80c5cb4a *****
Running test suite test_cmsis_apis
===================================================================
starting test - test_kernel_start
PASS - test_kernel_start
===================================================================
starting test - test_kernel_systick
PASS - test_kernel_systick
===================================================================
starting test - test_thread_apis
PASS - test_thread_apis
===================================================================
starting test - test_thread_prio
PASS - test_thread_prio
===================================================================
starting test - test_thread_instances
PASS - test_thread_instances
===================================================================
starting test - test_timer
oneshot_callback (Timer 1) = 1
periodic_callback (Timer 2) = 1
periodic_callback (Timer 2) = 2
periodic_callback (Timer 2) = 3
periodic_callback (Timer 2) = 4
periodic_callback (Timer 2) = 5
periodic_callback (Timer 2) = 6
PASS - test_timer
===================================================================
starting test - test_mutex
PASS - test_mutex
===================================================================
starting test - test_mutex_lock_timeout
ASSERTION FAIL [mutex->owner == _kernel.current] @ /home/buildslave/src/github.com/zephyrproject-rtos/zephyr/kernel/mutex.c:217:

Steps to reproduce:

cd zephyr/tests/cmsis_rtos_v1/
rm -rf build && mkdir build && cd build
cmake -D BOARD=qemu_x86 ../
make BOARD=qemu_x86 run

Check the console log.
@rgundi

This comment has been minimized.

Copy link
Contributor

commented Aug 23, 2018

There's no specific mention in the CMSIS spec which tells what error value should be returned when a thread tries releasing a mutex which was obtained by some other thread. The underlying zephyr implementation does that check anyway which is the assert you are seeing. So, i think there's no point in adding the code snippet that tests this.

@rgundi rgundi closed this Aug 23, 2018

@pswarnak pswarnak reopened this Sep 7, 2018

@pswarnak pswarnak added this to the v1.14.0 milestone Sep 7, 2018

@nashif nashif added the priority: low label Sep 7, 2018

rgundi added a commit to rgundi/zephyr that referenced this issue Sep 8, 2018

lib/cmsis_rtos_v1: Check for mutex owner in cmsis
Check for the mutex owner in the cmsis layer itself while releasing.
Fixes zephyrproject-rtos#9574.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>

rgundi added a commit to rgundi/zephyr that referenced this issue Sep 8, 2018

lib/cmsis_rtos_v1: Check for mutex owner in cmsis layer
Check for the mutex owner in the cmsis layer itself while releasing.
Fixes zephyrproject-rtos#9574.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>

@nashif nashif closed this in #9859 Sep 9, 2018

nashif added a commit that referenced this issue Sep 9, 2018

lib/cmsis_rtos_v1: Check for mutex owner in cmsis layer
Check for the mutex owner in the cmsis layer itself while releasing.
Fixes #9574.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.