From patchwork Mon Apr 27 17:56:34 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Hatle X-Patchwork-Id: 87016 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28BFEFF8871 for ; Mon, 27 Apr 2026 17:56:59 +0000 (UTC) Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.2116.1777312611172297058 for ; Mon, 27 Apr 2026 10:56:51 -0700 Authentication-Results: mx.groups.io; dkim=none (message not signed); spf=pass (domain: kernel.crashing.org, ip: 63.228.1.57, mailfrom: mark.hatle@kernel.crashing.org) Received: from kernel.crashing.org.net (70-99-78-136.nuveramail.net [70.99.78.136] (may be forged)) by gate.crashing.org (8.18.1/8.18.1/Debian-2) with ESMTP id 63RHugAh876837; Mon, 27 Apr 2026 12:56:44 -0500 From: Mark Hatle To: yocto-patches@lists.yoctoproject.org, richard.purdie@linuxfoundation.org Cc: dburgener@linux.microsoft.com, peter.kjellerstedt@axis.com Subject: [pseudo][PATCH 04/11] test: Add fts test case Date: Mon, 27 Apr 2026 12:56:34 -0500 Message-Id: <1777312601-1393-5-git-send-email-mark.hatle@kernel.crashing.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1777312601-1393-1-git-send-email-mark.hatle@kernel.crashing.org> References: <1777312601-1393-1-git-send-email-mark.hatle@kernel.crashing.org> List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Mon, 27 Apr 2026 17:56:59 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto-patches/message/3850 From: Mark Hatle AI-Generated: test cases generated by github copilot (claude opus 6.4) Signed-off-by: Mark Hatle Signed-off-by: Mark Hatle --- test/test-fts.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/test-fts.sh | 8 ++++++ 2 files changed, 95 insertions(+) create mode 100644 test/test-fts.c create mode 100755 test/test-fts.sh diff --git a/test/test-fts.c b/test/test-fts.c new file mode 100644 index 0000000..38dfb87 --- /dev/null +++ b/test/test-fts.c @@ -0,0 +1,87 @@ +/* + * Test fts_open and related functions + * SPDX-License-Identifier: LGPL-2.1-only + */ +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include + +static int failures = 0; + +static void check(const char *desc, int condition) { + if (!condition) { + fprintf(stderr, "FAIL: %s\n", desc); + failures++; + } +} + +int main(void) { + FTS *ftsp; + FTSENT *p; + int fd; + int file_count = 0; + int dir_count = 0; + + /* Create test directory tree */ + mkdir("test_fts_dir", 0755); + mkdir("test_fts_dir/sub1", 0755); + mkdir("test_fts_dir/sub2", 0755); + fd = open("test_fts_dir/file1", O_CREAT | O_WRONLY, 0644); + close(fd); + fd = open("test_fts_dir/sub1/file2", O_CREAT | O_WRONLY, 0644); + close(fd); + + /* Set ownership so we can check pseudo tracks it through fts */ + check("chown file1", chown("test_fts_dir/file1", 100, 200) == 0); + check("chown file2", chown("test_fts_dir/sub1/file2", 300, 400) == 0); + + /* fts_open */ + { + char *paths[] = { "test_fts_dir", NULL }; + ftsp = fts_open(paths, FTS_PHYSICAL | FTS_NOCHDIR, NULL); + check("fts_open", ftsp != NULL); + } + + /* Walk the tree */ + while ((p = fts_read(ftsp)) != NULL) { + switch (p->fts_info) { + case FTS_F: + file_count++; + if (strcmp(p->fts_name, "file1") == 0) { + check("fts file1 uid", p->fts_statp->st_uid == 100); + check("fts file1 gid", p->fts_statp->st_gid == 200); + } + if (strcmp(p->fts_name, "file2") == 0) { + check("fts file2 uid", p->fts_statp->st_uid == 300); + check("fts file2 gid", p->fts_statp->st_gid == 400); + } + break; + case FTS_D: + dir_count++; + break; + default: + break; + } + } + + check("fts found 2 files", file_count == 2); + check("fts found dirs", dir_count >= 3); /* test_fts_dir, sub1, sub2 */ + + fts_close(ftsp); + + /* Cleanup */ + unlink("test_fts_dir/sub1/file2"); + unlink("test_fts_dir/file1"); + rmdir("test_fts_dir/sub1"); + rmdir("test_fts_dir/sub2"); + rmdir("test_fts_dir"); + + return failures; +} diff --git a/test/test-fts.sh b/test/test-fts.sh new file mode 100755 index 0000000..50413c8 --- /dev/null +++ b/test/test-fts.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# +# Test fts_open and tree walking + +rm -rf test_fts_dir +./test/test-fts