tests: posix: common: separate posix c_lib_ext to standalone test
posix.common contains testsuites that can be separated into smaller groups of tests. This change moves fnmatch, getopt and getentropy into a singular testsuite at tests/posix/c_lib_ext app directory. Signed-off-by: Marvin Ouma <pancakesdeath@protonmail.com>
This commit is contained in:
parent
18fd49ea0e
commit
3977703ebb
12 changed files with 88 additions and 161 deletions
|
@ -1,10 +1,12 @@
|
||||||
# Copyright (c) 2024 Google LLC
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.20.0)
|
cmake_minimum_required(VERSION 3.20.0)
|
||||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||||
project(getentropy)
|
project(posix_c_lib_ext)
|
||||||
|
|
||||||
FILE(GLOB app_sources src/*.c)
|
FILE(GLOB app_sources src/*.c)
|
||||||
|
|
||||||
target_sources(app PRIVATE ${app_sources})
|
target_sources(app PRIVATE ${app_sources})
|
||||||
|
|
||||||
|
target_include_directories(app PRIVATE ${ZEPHYR_BASE}/lib/posix/options/getopt)
|
||||||
|
target_compile_options(app PRIVATE -U_POSIX_C_SOURCE -D_POSIX_C_SOURCE=200809L)
|
|
@ -1,3 +1,5 @@
|
||||||
CONFIG_ENTROPY_GENERATOR=y
|
|
||||||
CONFIG_POSIX_C_LIB_EXT=y
|
|
||||||
CONFIG_ZTEST=y
|
CONFIG_ZTEST=y
|
||||||
|
|
||||||
|
CONFIG_POSIX_C_LIB_EXT=y
|
||||||
|
CONFIG_GETOPT_LONG=y
|
||||||
|
CONFIG_ENTROPY_GENERATOR=y
|
|
@ -4,15 +4,14 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <fnmatch.h>
|
#include <zephyr/posix/fnmatch.h>
|
||||||
|
|
||||||
#include <zephyr/ztest.h>
|
#include <zephyr/ztest.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adapted from
|
* Adapted from
|
||||||
* https://git.musl-libc.org/cgit/libc-testsuite/tree/fnmatch.c
|
* https://git.musl-libc.org/cgit/libc-testsuite/tree/fnmatch.c
|
||||||
*/
|
*/
|
||||||
ZTEST(fnmatch, test_fnmatch)
|
ZTEST(posix_c_lib_ext, test_fnmatch)
|
||||||
{
|
{
|
||||||
/* Note: commented out lines indicate known problems to be addressed in #55186 */
|
/* Note: commented out lines indicate known problems to be addressed in #55186 */
|
||||||
|
|
||||||
|
@ -82,5 +81,3 @@ ZTEST(fnmatch, test_fnmatch)
|
||||||
zassert_ok(fnmatch("a*b", "a.b", FNM_PATHNAME | FNM_PERIOD));
|
zassert_ok(fnmatch("a*b", "a.b", FNM_PATHNAME | FNM_PERIOD));
|
||||||
zassert_ok(fnmatch("a[.]b", "a.b", FNM_PATHNAME | FNM_PERIOD));
|
zassert_ok(fnmatch("a[.]b", "a.b", FNM_PATHNAME | FNM_PERIOD));
|
||||||
}
|
}
|
||||||
|
|
||||||
ZTEST_SUITE(fnmatch, NULL, NULL, NULL, NULL, NULL);
|
|
|
@ -4,13 +4,12 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <zephyr/posix/unistd.h>
|
||||||
#include <zephyr/ztest.h>
|
#include <zephyr/ztest.h>
|
||||||
|
|
||||||
#include <zephyr/posix/unistd.h>
|
ZTEST(posix_c_lib_ext, test_getentropy_too_large)
|
||||||
|
|
||||||
ZTEST(getentropy_test_suite, test_getentropy_too_large)
|
|
||||||
{
|
{
|
||||||
uint8_t buf[256 + 1] = { 0 };
|
uint8_t buf[256 + 1] = {0};
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = getentropy(buf, sizeof(buf));
|
ret = getentropy(buf, sizeof(buf));
|
||||||
|
@ -18,7 +17,7 @@ ZTEST(getentropy_test_suite, test_getentropy_too_large)
|
||||||
zassert_equal(errno, EIO);
|
zassert_equal(errno, EIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZTEST(getentropy_test_suite, test_getentropy_null_buffer)
|
ZTEST(posix_c_lib_ext, test_getentropy_null_buffer)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -27,18 +26,18 @@ ZTEST(getentropy_test_suite, test_getentropy_null_buffer)
|
||||||
zassert_equal(errno, EFAULT);
|
zassert_equal(errno, EFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZTEST(getentropy_test_suite, test_getentropy_max_size)
|
ZTEST(posix_c_lib_ext, test_getentropy_max_size)
|
||||||
{
|
{
|
||||||
uint8_t buf[256] = { 0 };
|
uint8_t buf[256] = {0};
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = getentropy(buf, sizeof(buf));
|
ret = getentropy(buf, sizeof(buf));
|
||||||
zassert_equal(ret, 0);
|
zassert_equal(ret, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZTEST(getentropy_test_suite, test_getentropy)
|
ZTEST(posix_c_lib_ext, test_getentropy)
|
||||||
{
|
{
|
||||||
uint8_t zero[16] = { 0 };
|
uint8_t zero[16] = {0};
|
||||||
uint8_t buf1[16];
|
uint8_t buf1[16];
|
||||||
uint8_t buf2[16];
|
uint8_t buf2[16];
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -53,5 +52,3 @@ ZTEST(getentropy_test_suite, test_getentropy)
|
||||||
zassert_true(memcmp(buf2, zero, sizeof(zero)) != 0);
|
zassert_true(memcmp(buf2, zero, sizeof(zero)) != 0);
|
||||||
zassert_true(memcmp(buf1, buf2, sizeof(buf1)) != 0);
|
zassert_true(memcmp(buf1, buf2, sizeof(buf1)) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZTEST_SUITE(getentropy_test_suite, NULL, NULL, NULL, NULL, NULL);
|
|
|
@ -9,27 +9,17 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <zephyr/kernel.h>
|
|
||||||
#include <zephyr/ztest.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <zephyr/posix/unistd.h>
|
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
ZTEST_SUITE(getopt_test_suite, NULL, NULL, NULL, NULL, NULL);
|
#include <zephyr/kernel.h>
|
||||||
|
#include <zephyr/posix/unistd.h>
|
||||||
|
#include <zephyr/ztest.h>
|
||||||
|
|
||||||
ZTEST(getopt_test_suite, test_getopt_basic)
|
ZTEST(posix_c_lib_ext, test_getopt_basic)
|
||||||
{
|
{
|
||||||
static const char *const nargv[] = {
|
static const char *const nargv[] = {
|
||||||
"cmd_name",
|
"cmd_name", "-b", "-a", "-h", "-c", "-l", "-h", "-a", "-i", "-w",
|
||||||
"-b",
|
|
||||||
"-a",
|
|
||||||
"-h",
|
|
||||||
"-c",
|
|
||||||
"-l",
|
|
||||||
"-h",
|
|
||||||
"-a",
|
|
||||||
"-i",
|
|
||||||
"-w",
|
|
||||||
};
|
};
|
||||||
static const char *accepted_opt = "abchw";
|
static const char *accepted_opt = "abchw";
|
||||||
static const char *expected = "bahc?ha?w";
|
static const char *expected = "bahc?ha?w";
|
||||||
|
@ -63,7 +53,7 @@ enum getopt_idx {
|
||||||
GETOPT_IDX_OPTARG
|
GETOPT_IDX_OPTARG
|
||||||
};
|
};
|
||||||
|
|
||||||
ZTEST(getopt_test_suite, test_getopt)
|
ZTEST(posix_c_lib_ext, test_getopt)
|
||||||
{
|
{
|
||||||
struct getopt_state *state;
|
struct getopt_state *state;
|
||||||
static const char *test_opts = "ac:";
|
static const char *test_opts = "ac:";
|
||||||
|
@ -96,8 +86,7 @@ ZTEST(getopt_test_suite, test_getopt)
|
||||||
zassert_equal(0, strcmp(argv[GETOPT_IDX_OPTARG], state->optarg),
|
zassert_equal(0, strcmp(argv[GETOPT_IDX_OPTARG], state->optarg),
|
||||||
"unexpected optarg result");
|
"unexpected optarg result");
|
||||||
/* Non thread safe usage: */
|
/* Non thread safe usage: */
|
||||||
zassert_equal(0, strcmp(argv[GETOPT_IDX_OPTARG], optarg),
|
zassert_equal(0, strcmp(argv[GETOPT_IDX_OPTARG], optarg), "unexpected optarg result");
|
||||||
"unexpected optarg result");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum getopt_long_idx {
|
enum getopt_long_idx {
|
||||||
|
@ -107,7 +96,7 @@ enum getopt_long_idx {
|
||||||
GETOPT_LONG_IDX_OPTARG
|
GETOPT_LONG_IDX_OPTARG
|
||||||
};
|
};
|
||||||
|
|
||||||
ZTEST(getopt_test_suite, test_getopt_long)
|
ZTEST(posix_c_lib_ext, test_getopt_long)
|
||||||
{
|
{
|
||||||
/* Below test is based on example
|
/* Below test is based on example
|
||||||
* https://www.gnu.org/software/libc/manual/html_node/Getopt-Long-Option-Example.html
|
* https://www.gnu.org/software/libc/manual/html_node/Getopt-Long-Option-Example.html
|
||||||
|
@ -120,16 +109,16 @@ ZTEST(getopt_test_suite, test_getopt_long)
|
||||||
int c;
|
int c;
|
||||||
struct option long_options[] = {
|
struct option long_options[] = {
|
||||||
/* These options set a flag. */
|
/* These options set a flag. */
|
||||||
{"verbose", no_argument, &verbose_flag, 1},
|
{"verbose", no_argument, &verbose_flag, 1},
|
||||||
{"brief", no_argument, &verbose_flag, 0},
|
{"brief", no_argument, &verbose_flag, 0},
|
||||||
/* These options don’t set a flag.
|
/* These options don’t set a flag.
|
||||||
* We distinguish them by their indices.
|
* We distinguish them by their indices.
|
||||||
*/
|
*/
|
||||||
{"add", no_argument, 0, 'a'},
|
{"add", no_argument, 0, 'a'},
|
||||||
{"create", required_argument, 0, 'c'},
|
{"create", required_argument, 0, 'c'},
|
||||||
{"delete", required_argument, 0, 'd'},
|
{"delete", required_argument, 0, 'd'},
|
||||||
{"long", required_argument, 0, 'e'},
|
{"long", required_argument, 0, 'e'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0},
|
||||||
};
|
};
|
||||||
static const char *accepted_opt = "ac:d:e:";
|
static const char *accepted_opt = "ac:d:e:";
|
||||||
|
|
||||||
|
@ -170,64 +159,51 @@ ZTEST(getopt_test_suite, test_getopt_long)
|
||||||
/* Get state of the current thread */
|
/* Get state of the current thread */
|
||||||
getopt_init();
|
getopt_init();
|
||||||
argv = (char **)argv1;
|
argv = (char **)argv1;
|
||||||
c = getopt_long(argc1, argv, accepted_opt,
|
c = getopt_long(argc1, argv, accepted_opt, long_options, &option_index);
|
||||||
long_options, &option_index);
|
|
||||||
zassert_equal(verbose_flag, 1, "verbose flag expected");
|
zassert_equal(verbose_flag, 1, "verbose flag expected");
|
||||||
c = getopt_long(argc1, argv, accepted_opt, long_options, &option_index);
|
c = getopt_long(argc1, argv, accepted_opt, long_options, &option_index);
|
||||||
state = getopt_state_get();
|
state = getopt_state_get();
|
||||||
zassert_equal('c', c, "unexpected option");
|
zassert_equal('c', c, "unexpected option");
|
||||||
zassert_equal(0, strcmp(state->optarg, argv[GETOPT_LONG_IDX_OPTARG]),
|
zassert_equal(0, strcmp(state->optarg, argv[GETOPT_LONG_IDX_OPTARG]), "unexpected optarg");
|
||||||
"unexpected optarg");
|
c = getopt_long(argc1, argv, accepted_opt, long_options, &option_index);
|
||||||
c = getopt_long(argc1, argv, accepted_opt,
|
|
||||||
long_options, &option_index);
|
|
||||||
zassert_equal(-1, c, "getopt_long shall return -1");
|
zassert_equal(-1, c, "getopt_long shall return -1");
|
||||||
|
|
||||||
/* Test scenario 2 */
|
/* Test scenario 2 */
|
||||||
argv = (char **)argv2;
|
argv = (char **)argv2;
|
||||||
getopt_init();
|
getopt_init();
|
||||||
c = getopt_long(argc2, argv, accepted_opt,
|
c = getopt_long(argc2, argv, accepted_opt, long_options, &option_index);
|
||||||
long_options, &option_index);
|
|
||||||
zassert_equal(verbose_flag, 0, "verbose flag expected");
|
zassert_equal(verbose_flag, 0, "verbose flag expected");
|
||||||
c = getopt_long(argc2, argv, accepted_opt,
|
c = getopt_long(argc2, argv, accepted_opt, long_options, &option_index);
|
||||||
long_options, &option_index);
|
|
||||||
zassert_equal('d', c, "unexpected option");
|
zassert_equal('d', c, "unexpected option");
|
||||||
state = getopt_state_get();
|
state = getopt_state_get();
|
||||||
zassert_equal(0, strcmp(state->optarg, argv[GETOPT_LONG_IDX_OPTARG]),
|
zassert_equal(0, strcmp(state->optarg, argv[GETOPT_LONG_IDX_OPTARG]), "unexpected optarg");
|
||||||
"unexpected optarg");
|
c = getopt_long(argc2, argv, accepted_opt, long_options, &option_index);
|
||||||
c = getopt_long(argc2, argv, accepted_opt,
|
|
||||||
long_options, &option_index);
|
|
||||||
zassert_equal(-1, c, "getopt_long shall return -1");
|
zassert_equal(-1, c, "getopt_long shall return -1");
|
||||||
|
|
||||||
/* Test scenario 3 */
|
/* Test scenario 3 */
|
||||||
argv = (char **)argv3;
|
argv = (char **)argv3;
|
||||||
getopt_init();
|
getopt_init();
|
||||||
c = getopt_long(argc3, argv, accepted_opt,
|
c = getopt_long(argc3, argv, accepted_opt, long_options, &option_index);
|
||||||
long_options, &option_index);
|
|
||||||
zassert_equal(verbose_flag, 0, "verbose flag expected");
|
zassert_equal(verbose_flag, 0, "verbose flag expected");
|
||||||
c = getopt_long(argc3, argv, accepted_opt,
|
c = getopt_long(argc3, argv, accepted_opt, long_options, &option_index);
|
||||||
long_options, &option_index);
|
|
||||||
zassert_equal('a', c, "unexpected option");
|
zassert_equal('a', c, "unexpected option");
|
||||||
c = getopt_long(argc3, argv, accepted_opt,
|
c = getopt_long(argc3, argv, accepted_opt, long_options, &option_index);
|
||||||
long_options, &option_index);
|
|
||||||
zassert_equal(-1, c, "getopt_long shall return -1");
|
zassert_equal(-1, c, "getopt_long shall return -1");
|
||||||
|
|
||||||
/* Test scenario 4 */
|
/* Test scenario 4 */
|
||||||
argv = (char **)argv4;
|
argv = (char **)argv4;
|
||||||
getopt_init();
|
getopt_init();
|
||||||
c = getopt_long(argc4, argv, accepted_opt,
|
c = getopt_long(argc4, argv, accepted_opt, long_options, &option_index);
|
||||||
long_options, &option_index);
|
|
||||||
zassert_equal(verbose_flag, 0, "verbose flag expected");
|
zassert_equal(verbose_flag, 0, "verbose flag expected");
|
||||||
c = getopt_long(argc4, argv, accepted_opt,
|
c = getopt_long(argc4, argv, accepted_opt, long_options, &option_index);
|
||||||
long_options, &option_index);
|
|
||||||
/* Function was called with option '-l'. It is expected it will be
|
/* Function was called with option '-l'. It is expected it will be
|
||||||
* NOT evaluated to '--long' which has flag 'e'.
|
* NOT evaluated to '--long' which has flag 'e'.
|
||||||
*/
|
*/
|
||||||
zassert_not_equal('e', c, "unexpected option match");
|
zassert_not_equal('e', c, "unexpected option match");
|
||||||
c = getopt_long(argc4, argv, accepted_opt,
|
c = getopt_long(argc4, argv, accepted_opt, long_options, &option_index);
|
||||||
long_options, &option_index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ZTEST(getopt_test_suite, test_getopt_long_only)
|
ZTEST(posix_c_lib_ext, test_getopt_long_only)
|
||||||
{
|
{
|
||||||
/* Below test is based on example
|
/* Below test is based on example
|
||||||
* https://www.gnu.org/software/libc/manual/html_node/Getopt-Long-Option-Example.html
|
* https://www.gnu.org/software/libc/manual/html_node/Getopt-Long-Option-Example.html
|
||||||
|
@ -240,16 +216,16 @@ ZTEST(getopt_test_suite, test_getopt_long_only)
|
||||||
int c;
|
int c;
|
||||||
struct option long_options[] = {
|
struct option long_options[] = {
|
||||||
/* These options set a flag. */
|
/* These options set a flag. */
|
||||||
{"verbose", no_argument, &verbose_flag, 1},
|
{"verbose", no_argument, &verbose_flag, 1},
|
||||||
{"brief", no_argument, &verbose_flag, 0},
|
{"brief", no_argument, &verbose_flag, 0},
|
||||||
/* These options don’t set a flag.
|
/* These options don’t set a flag.
|
||||||
* We distinguish them by their indices.
|
* We distinguish them by their indices.
|
||||||
*/
|
*/
|
||||||
{"add", no_argument, 0, 'a'},
|
{"add", no_argument, 0, 'a'},
|
||||||
{"create", required_argument, 0, 'c'},
|
{"create", required_argument, 0, 'c'},
|
||||||
{"delete", required_argument, 0, 'd'},
|
{"delete", required_argument, 0, 'd'},
|
||||||
{"long", required_argument, 0, 'e'},
|
{"long", required_argument, 0, 'e'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0},
|
||||||
};
|
};
|
||||||
static const char *accepted_opt = "ac:d:e:";
|
static const char *accepted_opt = "ac:d:e:";
|
||||||
|
|
||||||
|
@ -289,62 +265,48 @@ ZTEST(getopt_test_suite, test_getopt_long_only)
|
||||||
/* Test scenario 1 */
|
/* Test scenario 1 */
|
||||||
argv = (char **)argv1;
|
argv = (char **)argv1;
|
||||||
getopt_init();
|
getopt_init();
|
||||||
c = getopt_long_only(argc1, argv, accepted_opt,
|
c = getopt_long_only(argc1, argv, accepted_opt, long_options, &option_index);
|
||||||
long_options, &option_index);
|
|
||||||
zassert_equal(verbose_flag, 1, "verbose flag expected");
|
zassert_equal(verbose_flag, 1, "verbose flag expected");
|
||||||
c = getopt_long_only(argc1, argv, accepted_opt,
|
c = getopt_long_only(argc1, argv, accepted_opt, long_options, &option_index);
|
||||||
long_options, &option_index);
|
|
||||||
state = getopt_state_get();
|
state = getopt_state_get();
|
||||||
zassert_equal('c', c, "unexpected option");
|
zassert_equal('c', c, "unexpected option");
|
||||||
zassert_equal(0, strcmp(state->optarg, argv[GETOPT_LONG_IDX_OPTARG]),
|
zassert_equal(0, strcmp(state->optarg, argv[GETOPT_LONG_IDX_OPTARG]), "unexpected optarg");
|
||||||
"unexpected optarg");
|
c = getopt_long_only(argc1, argv, accepted_opt, long_options, &option_index);
|
||||||
c = getopt_long_only(argc1, argv, accepted_opt,
|
|
||||||
long_options, &option_index);
|
|
||||||
zassert_equal(-1, c, "getopt_long_only shall return -1");
|
zassert_equal(-1, c, "getopt_long_only shall return -1");
|
||||||
|
|
||||||
/* Test scenario 2 */
|
/* Test scenario 2 */
|
||||||
argv = (char **)argv2;
|
argv = (char **)argv2;
|
||||||
getopt_init();
|
getopt_init();
|
||||||
state = getopt_state_get();
|
state = getopt_state_get();
|
||||||
c = getopt_long_only(argc2, argv, accepted_opt,
|
c = getopt_long_only(argc2, argv, accepted_opt, long_options, &option_index);
|
||||||
long_options, &option_index);
|
|
||||||
zassert_equal(verbose_flag, 0, "verbose flag expected");
|
zassert_equal(verbose_flag, 0, "verbose flag expected");
|
||||||
c = getopt_long_only(argc2, argv, accepted_opt,
|
c = getopt_long_only(argc2, argv, accepted_opt, long_options, &option_index);
|
||||||
long_options, &option_index);
|
|
||||||
state = getopt_state_get();
|
state = getopt_state_get();
|
||||||
zassert_equal('d', c, "unexpected option");
|
zassert_equal('d', c, "unexpected option");
|
||||||
zassert_equal(0, strcmp(state->optarg, argv[GETOPT_LONG_IDX_OPTARG]),
|
zassert_equal(0, strcmp(state->optarg, argv[GETOPT_LONG_IDX_OPTARG]), "unexpected optarg");
|
||||||
"unexpected optarg");
|
c = getopt_long_only(argc2, argv, accepted_opt, long_options, &option_index);
|
||||||
c = getopt_long_only(argc2, argv, accepted_opt,
|
|
||||||
long_options, &option_index);
|
|
||||||
zassert_equal(-1, c, "getopt_long_only shall return -1");
|
zassert_equal(-1, c, "getopt_long_only shall return -1");
|
||||||
|
|
||||||
/* Test scenario 3 */
|
/* Test scenario 3 */
|
||||||
argv = (char **)argv3;
|
argv = (char **)argv3;
|
||||||
getopt_init();
|
getopt_init();
|
||||||
c = getopt_long_only(argc3, argv, accepted_opt,
|
c = getopt_long_only(argc3, argv, accepted_opt, long_options, &option_index);
|
||||||
long_options, &option_index);
|
|
||||||
zassert_equal(verbose_flag, 0, "verbose flag expected");
|
zassert_equal(verbose_flag, 0, "verbose flag expected");
|
||||||
c = getopt_long_only(argc3, argv, accepted_opt,
|
c = getopt_long_only(argc3, argv, accepted_opt, long_options, &option_index);
|
||||||
long_options, &option_index);
|
|
||||||
zassert_equal('a', c, "unexpected option");
|
zassert_equal('a', c, "unexpected option");
|
||||||
c = getopt_long_only(argc3, argv, accepted_opt,
|
c = getopt_long_only(argc3, argv, accepted_opt, long_options, &option_index);
|
||||||
long_options, &option_index);
|
|
||||||
zassert_equal(-1, c, "getopt_long_only shall return -1");
|
zassert_equal(-1, c, "getopt_long_only shall return -1");
|
||||||
|
|
||||||
/* Test scenario 4 */
|
/* Test scenario 4 */
|
||||||
argv = (char **)argv4;
|
argv = (char **)argv4;
|
||||||
getopt_init();
|
getopt_init();
|
||||||
c = getopt_long_only(argc4, argv, accepted_opt,
|
c = getopt_long_only(argc4, argv, accepted_opt, long_options, &option_index);
|
||||||
long_options, &option_index);
|
|
||||||
zassert_equal(verbose_flag, 0, "verbose flag expected");
|
zassert_equal(verbose_flag, 0, "verbose flag expected");
|
||||||
c = getopt_long_only(argc4, argv, accepted_opt,
|
c = getopt_long_only(argc4, argv, accepted_opt, long_options, &option_index);
|
||||||
long_options, &option_index);
|
|
||||||
|
|
||||||
/* Function was called with option '-l'. It is expected it will be
|
/* Function was called with option '-l'. It is expected it will be
|
||||||
* evaluated to '--long' which has flag 'e'.
|
* evaluated to '--long' which has flag 'e'.
|
||||||
*/
|
*/
|
||||||
zassert_equal('e', c, "unexpected option");
|
zassert_equal('e', c, "unexpected option");
|
||||||
c = getopt_long_only(argc4, argv, accepted_opt,
|
c = getopt_long_only(argc4, argv, accepted_opt, long_options, &option_index);
|
||||||
long_options, &option_index);
|
|
||||||
}
|
}
|
9
tests/posix/c_lib_ext/src/main.c
Normal file
9
tests/posix/c_lib_ext/src/main.c
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Marvin Ouma <pancakesdeath@protonmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <zephyr/ztest.h>
|
||||||
|
|
||||||
|
ZTEST_SUITE(posix_c_lib_ext, NULL, NULL, NULL, NULL, NULL);
|
|
@ -3,32 +3,34 @@ common:
|
||||||
not CONFIG_NATIVE_LIBC
|
not CONFIG_NATIVE_LIBC
|
||||||
tags:
|
tags:
|
||||||
- posix
|
- posix
|
||||||
- getentropy
|
- c_lib_ext
|
||||||
# 1 tier0 platform per supported architecture
|
# 1 tier0 platform per supported architecture
|
||||||
platform_key:
|
platform_key:
|
||||||
- arch
|
- arch
|
||||||
- simulation
|
- simulation
|
||||||
|
min_flash: 64
|
||||||
|
min_ram: 32
|
||||||
tests:
|
tests:
|
||||||
portability.posix.getentropy:
|
portability.posix.c_lib_ext:
|
||||||
extra_configs:
|
extra_configs:
|
||||||
- CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=256
|
- CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=256
|
||||||
portability.posix.getentropy.armclang_std_libc:
|
portability.posix.c_lib_ext.armclang_std_libc:
|
||||||
toolchain_allow: armclang
|
toolchain_allow: armclang
|
||||||
extra_configs:
|
extra_configs:
|
||||||
- CONFIG_ARMCLANG_STD_LIBC=y
|
- CONFIG_ARMCLANG_STD_LIBC=y
|
||||||
portability.posix.getentropy.arcmwdtlib:
|
portability.posix.c_lib_ext.arcmwdtlib:
|
||||||
toolchain_allow: arcmwdt
|
toolchain_allow: arcmwdt
|
||||||
extra_configs:
|
extra_configs:
|
||||||
- CONFIG_ARCMWDT_LIBC=y
|
- CONFIG_ARCMWDT_LIBC=y
|
||||||
portability.posix.getentropy.minimal:
|
portability.posix.c_lib_ext.minimal:
|
||||||
extra_configs:
|
extra_configs:
|
||||||
- CONFIG_MINIMAL_LIBC=y
|
- CONFIG_MINIMAL_LIBC=y
|
||||||
- CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=256
|
- CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=256
|
||||||
portability.posix.getentropy.newlib:
|
portability.posix.c_lib_ext.newlib:
|
||||||
filter: TOOLCHAIN_HAS_NEWLIB == 1
|
filter: TOOLCHAIN_HAS_NEWLIB == 1
|
||||||
extra_configs:
|
extra_configs:
|
||||||
- CONFIG_NEWLIB_LIBC=y
|
- CONFIG_NEWLIB_LIBC=y
|
||||||
portability.posix.getentropy.picolibc:
|
portability.posix.c_lib_ext.picolibc:
|
||||||
tags: picolibc
|
tags: picolibc
|
||||||
filter: CONFIG_PICOLIBC_SUPPORTED
|
filter: CONFIG_PICOLIBC_SUPPORTED
|
||||||
extra_configs:
|
extra_configs:
|
|
@ -1,8 +0,0 @@
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.20.0)
|
|
||||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
|
||||||
project(getopt)
|
|
||||||
|
|
||||||
FILE(GLOB app_sources src/*.c)
|
|
||||||
target_sources(app PRIVATE ${app_sources})
|
|
|
@ -1 +0,0 @@
|
||||||
CONFIG_NEWLIB_LIBC_MIN_REQUIRED_HEAP_SIZE=1024
|
|
|
@ -1 +0,0 @@
|
||||||
CONFIG_NEWLIB_LIBC_MIN_REQUIRED_HEAP_SIZE=4096
|
|
|
@ -1,5 +0,0 @@
|
||||||
CONFIG_POSIX_C_LIB_EXT=y
|
|
||||||
CONFIG_GETOPT_LONG=y
|
|
||||||
CONFIG_LOG=n
|
|
||||||
CONFIG_ZTEST=y
|
|
||||||
CONFIG_TEST_LOGGING_DEFAULTS=n
|
|
|
@ -1,29 +0,0 @@
|
||||||
common:
|
|
||||||
filter: not CONFIG_NATIVE_LIBC
|
|
||||||
tags:
|
|
||||||
- posix
|
|
||||||
- getopt
|
|
||||||
# 1 tier0 platform per supported architecture
|
|
||||||
platform_key:
|
|
||||||
- arch
|
|
||||||
- simulation
|
|
||||||
min_flash: 64
|
|
||||||
min_ram: 32
|
|
||||||
tests:
|
|
||||||
portability.posix.getopt: {}
|
|
||||||
portability.posix.getopt.minimal:
|
|
||||||
extra_configs:
|
|
||||||
- CONFIG_MINIMAL_LIBC=y
|
|
||||||
portability.posix.getopt.newlib:
|
|
||||||
filter: TOOLCHAIN_HAS_NEWLIB == 1
|
|
||||||
extra_configs:
|
|
||||||
- CONFIG_NEWLIB_LIBC=y
|
|
||||||
portability.posix.getopt.picolibc:
|
|
||||||
tags: picolibc
|
|
||||||
filter: CONFIG_PICOLIBC_SUPPORTED
|
|
||||||
extra_configs:
|
|
||||||
- CONFIG_PICOLIBC=y
|
|
||||||
portability.posix.getopt.logger:
|
|
||||||
extra_configs:
|
|
||||||
- CONFIG_LOG=y
|
|
||||||
build_only: true
|
|
Loading…
Add table
Add a link
Reference in a new issue