From cc156b908e7d364d72144b25a484f9bd8e8b8099 Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Mon, 28 Feb 2022 15:41:53 +0800 Subject: [PATCH] ostest: Introduce basic setjmp/longjmp test Signed-off-by: Huang Qi --- testing/ostest/Makefile | 4 +++ testing/ostest/ostest.h | 4 +++ testing/ostest/ostest_main.c | 8 ++++++ testing/ostest/setjmp.c | 56 ++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 testing/ostest/setjmp.c diff --git a/testing/ostest/Makefile b/testing/ostest/Makefile index 976767562..c9e50181f 100644 --- a/testing/ostest/Makefile +++ b/testing/ostest/Makefile @@ -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 diff --git a/testing/ostest/ostest.h b/testing/ostest/ostest.h index 33a18c826..6c73e0807 100644 --- a/testing/ostest/ostest.h +++ b/testing/ostest/ostest.h @@ -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 */ diff --git a/testing/ostest/ostest_main.c b/testing/ostest/ostest_main.c index ecf57433c..eb8b06e71 100644 --- a/testing/ostest/ostest_main.c +++ b/testing/ostest/ostest_main.c @@ -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 */ diff --git a/testing/ostest/setjmp.c b/testing/ostest/setjmp.c new file mode 100644 index 000000000..406756967 --- /dev/null +++ b/testing/ostest/setjmp.c @@ -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 + +#include +#include +#include + +/**************************************************************************** + * 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"); + } +}