ostest: Introduce basic setjmp/longjmp test

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
Huang Qi 2022-02-28 15:41:53 +08:00 committed by Xiang Xiao
parent 9351ab50d5
commit cc156b908e
4 changed files with 72 additions and 0 deletions

View File

@ -119,4 +119,8 @@ CSRCS += prioinherit.c
endif # CONFIG_PRIORITY_INHERITANCE
endif # CONFIG_DISABLE_PTHREAD
ifeq ($(CONFIG_ARCH_SETJMP_H),y)
CSRCS += setjmp.c
endif
include $(APPDIR)/Application.mk

View File

@ -243,6 +243,10 @@ void priority_inheritance(void);
int vfork_test(void);
#endif
/* setjmp.c *****************************************************************/
void setjmp_test(void);
/* APIs exported (conditionally) by the OS specifically for testing of
* priority inheritance
*/

View File

@ -532,6 +532,14 @@ static int user_main(int argc, char *argv[])
check_test_memory_usage();
#endif
#ifdef CONFIG_ARCH_SETJMP_H
/* Verify setjmp/longjmp */
printf("\nuser_main: setjmp test\n");
setjmp_test();
check_test_memory_usage();
#endif
#if defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_DISABLE_PTHREAD)
/* Verify priority inheritance */

56
testing/ostest/setjmp.c Normal file
View File

@ -0,0 +1,56 @@
/****************************************************************************
* apps/testing/ostest/setjmp.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <assert.h>
#include <setjmp.h>
#include <stdio.h>
/****************************************************************************
* Public Functions
****************************************************************************/
void setjmp_test(void)
{
int value;
jmp_buf buf;
printf("setjmp_test: Initializing jmp_buf\n");
if ((value = setjmp(buf)) == 0)
{
printf("setjmp_test: Try jump\n");
longjmp(buf, 123);
/* Unreachable */
ASSERT(0);
}
else
{
ASSERT(value == 123);
printf("setjmp_test: Jump succeed\n");
}
}