Skip to content

Commit 3a55757

Browse files
committed
tests: posix: add POSIX_SYSTEM_DATABASE_R testsuite
Add a teststuite to exercise the POSIX_SYSTEM_DATABASE_R Option Group. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
1 parent ae91284 commit 3a55757

File tree

9 files changed

+416
-36
lines changed

9 files changed

+416
-36
lines changed

tests/posix/common/src/grp.c

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/posix/common/src/pwd.c

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/posix/fs/src/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#include <ff.h>
78
#include "test_fs.h"
89

910
ZTEST_SUITE(posix_fs_test, NULL, test_mount, NULL, NULL, test_unmount);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(posix_system_database_r)
6+
7+
FILE(GLOB app_sources src/*.c)
8+
target_sources(app PRIVATE ${app_sources})
9+
10+
target_compile_options(app PRIVATE -U_POSIX_C_SOURCE -D_POSIX_C_SOURCE=200809L)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2023 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
ramdisk0 {
9+
compatible = "zephyr,ram-disk";
10+
disk-name = "RAM";
11+
sector-size = <512>;
12+
sector-count = <160>;
13+
};
14+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CONFIG_POSIX_API=y
2+
CONFIG_ZTEST=y
3+
4+
CONFIG_POSIX_AEP_CHOICE_BASE=y
5+
CONFIG_POSIX_SYSTEM_DATABASE_R=y
6+
CONFIG_FAT_FILESYSTEM_ELM=y
7+
8+
CONFIG_MAIN_STACK_SIZE=4096
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2024 Tenstorrent AI ULC
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <string.h>
8+
9+
#include <ff.h>
10+
#include <zephyr/fs/fs.h>
11+
#include <zephyr/sys/util.h>
12+
#include <zephyr/ztest.h>
13+
14+
static FATFS _fs;
15+
16+
static struct fs_mount_t _mnt = {
17+
.type = FS_FATFS,
18+
.mnt_point = "/",
19+
.fs_data = &_fs,
20+
};
21+
22+
struct _entry {
23+
const char *const name;
24+
const char *const data;
25+
};
26+
27+
static const struct _entry _data[] = {
28+
{.name = "/etc/passwd",
29+
.data = "user:x:1000:1000:user:/home/user:/bin/sh\nroot:x:0:0:root:/root:/bin/sh\n"},
30+
{.name = "/etc/group", .data = "user:x:1000:staff,admin\nroot:x:0:\n"},
31+
};
32+
33+
void *setup(void)
34+
{
35+
int ret;
36+
37+
memset(&_fs, 0, sizeof(_fs));
38+
39+
ret = fs_mount(&_mnt);
40+
zassert_ok(ret, "mount failed: %d", ret);
41+
42+
ret = fs_mkdir("/etc");
43+
zassert_ok(ret, "mkdir failed: %d", ret);
44+
45+
ARRAY_FOR_EACH_PTR(_data, entry) {
46+
int len;
47+
struct fs_file_t zfp;
48+
49+
fs_file_t_init(&zfp);
50+
51+
ret = fs_open(&zfp, entry->name, FS_O_CREATE | FS_O_RDWR | FS_O_TRUNC);
52+
zassert_true(ret >= 0, "open failed: %d", ret);
53+
54+
len = strlen(entry->data);
55+
ret = fs_write(&zfp, entry->data, len);
56+
zassert_equal(ret, len, "%s returned %d instead of %d", "write", ret, len);
57+
58+
ret = fs_close(&zfp);
59+
zassert_ok(ret, "%s returned %d instead of %d", "close", ret, len);
60+
};
61+
62+
return &_mnt;
63+
}
64+
65+
void teardown(void *arg)
66+
{
67+
struct fs_mount_t *const mnt = arg;
68+
69+
(void)fs_unmount(mnt);
70+
}

0 commit comments

Comments
 (0)