From patchwork Sun Apr 2 18:04:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13197520 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D30DC7619A for ; Sun, 2 Apr 2023 18:04:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231316AbjDBSEr (ORCPT ); Sun, 2 Apr 2023 14:04:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230469AbjDBSEq (ORCPT ); Sun, 2 Apr 2023 14:04:46 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5756030F1; Sun, 2 Apr 2023 11:04:45 -0700 (PDT) From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1680458683; bh=VdplZ+maLIRLoILvVLhk3/Dt0NnSp9+Gg5MHvNvgDRw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BXFkLPbAaMWSTu/omAa6Y/mhMmuqfhq5K4cACX9Vgp7EeUr6XyWyuUPZzvQoIuWKU DiUbA8F3Q0FpS0FTRvSZHlCO5UkbxEN0l/WQMML8dKGAyr6CIf91Tb7sz24cH5Wjyj JalR+QBPFTo3raO2HR+N1Da/Jlx6A161G4Kpdu84= Date: Sun, 02 Apr 2023 18:04:34 +0000 Subject: [PATCH v3 1/4] tools/nolibc: add libc-test binary MIME-Version: 1.0 Message-Id: <20230328-nolibc-printf-test-v3-1-ddc79f92efd5@weissschuh.net> References: <20230328-nolibc-printf-test-v3-0-ddc79f92efd5@weissschuh.net> In-Reply-To: <20230328-nolibc-printf-test-v3-0-ddc79f92efd5@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1680458682; l=1521; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=VdplZ+maLIRLoILvVLhk3/Dt0NnSp9+Gg5MHvNvgDRw=; b=hRbD6xU9saIGMWt1sGt6Mi0mtKNW3F6bkYNL5ReSDde7wIy+bDoefllyjYGG7Yw5nJuMv9xU0 nzRT07XK5oMBll3kna9KXUOCgVga4xzAeVzcQ1jyt8g/t61Lcg/7Zs2 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org This can be used to easily compare the behavior of nolibc to the system libc. Signed-off-by: Thomas Weißschuh --- Feel free to drop this if it does not fit in. --- tools/testing/selftests/nolibc/.gitignore | 1 + tools/testing/selftests/nolibc/Makefile | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/tools/testing/selftests/nolibc/.gitignore b/tools/testing/selftests/nolibc/.gitignore index 4696df589d68..52f613cdad54 100644 --- a/tools/testing/selftests/nolibc/.gitignore +++ b/tools/testing/selftests/nolibc/.gitignore @@ -1,4 +1,5 @@ /initramfs/ +/libc-test /nolibc-test /run.out /sysroot/ diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index bbce57420465..903990d22ac8 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -128,6 +128,9 @@ nolibc-test: nolibc-test.c sysroot/$(ARCH)/include $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \ -nostdlib -static -Isysroot/$(ARCH)/include $< -lgcc +libc-test: nolibc-test.c + $(QUIET_CC)$(CC) -o $@ $< + # qemu user-land test run-user: nolibc-test $(Q)qemu-$(QEMU_ARCH) ./nolibc-test > "$(CURDIR)/run.out" || : @@ -159,6 +162,8 @@ clean: $(Q)rm -rf sysroot $(call QUIET_CLEAN, nolibc-test) $(Q)rm -f nolibc-test + $(call QUIET_CLEAN, libc-test) + $(Q)rm -f libc-test $(call QUIET_CLEAN, initramfs) $(Q)rm -rf initramfs $(call QUIET_CLEAN, run.out) From patchwork Sun Apr 2 18:04:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13197519 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0EE5C76196 for ; Sun, 2 Apr 2023 18:04:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230501AbjDBSEq (ORCPT ); Sun, 2 Apr 2023 14:04:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230478AbjDBSEq (ORCPT ); Sun, 2 Apr 2023 14:04:46 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 623EF4EFD; Sun, 2 Apr 2023 11:04:45 -0700 (PDT) From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1680458683; bh=WpL7AHZ/RVZDepQeqXUZNCLzamt9+Jfw6eToN9dbdkk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=t29kOegeu0yrjhaRhphXka1AJv8dp1R6T2UEglYfOBN5JIXWo3Q9SJmFcsDsQDEuF ooA+XcAvMvDprzbZF2KpELe5PRjtm3CXdd5KEvRW7A5cA7YGmbXm7Zabfr/Q7DeTSE PtrRZlfDJhJVKYc1GLhbgqLHm44AkBndUkXM/ots= Date: Sun, 02 Apr 2023 18:04:35 +0000 Subject: [PATCH v3 2/4] tools/nolibc: add wrapper for memfd_create MIME-Version: 1.0 Message-Id: <20230328-nolibc-printf-test-v3-2-ddc79f92efd5@weissschuh.net> References: <20230328-nolibc-printf-test-v3-0-ddc79f92efd5@weissschuh.net> In-Reply-To: <20230328-nolibc-printf-test-v3-0-ddc79f92efd5@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1680458682; l=1058; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=WpL7AHZ/RVZDepQeqXUZNCLzamt9+Jfw6eToN9dbdkk=; b=SWX0F2lLJt4IidEUS718+TFzjJz9Pt8aypgXLOk79aZ2l1abVew2uqgb+bV2rFVC2NcVhXha6 dIhXOgzygv9DKZ6qqz/3ByATgmcR1k5WdkEEHId4zEFV6yOHIK3/v3H X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org This is useful for users and will also be used by a future testcase. Signed-off-by: Thomas Weißschuh --- tools/include/nolibc/sys.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 5d624dc63a42..bea9760dbd16 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -1365,6 +1365,29 @@ ssize_t write(int fd, const void *buf, size_t count) return ret; } + +/* + * int memfd_create(const char *name, unsigned int flags); + */ + +static __attribute__((unused)) +int sys_memfd_create(const char *name, unsigned int flags) +{ + return my_syscall2(__NR_memfd_create, name, flags); +} + +static __attribute__((unused)) +int memfd_create(const char *name, unsigned int flags) +{ + ssize_t ret = sys_memfd_create(name, flags); + + if (ret < 0) { + SET_ERRNO(-ret); + ret = -1; + } + return ret; +} + /* make sure to include all global symbols */ #include "nolibc.h" From patchwork Sun Apr 2 18:04:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13197523 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1C96C77B6F for ; Sun, 2 Apr 2023 18:04:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231348AbjDBSEt (ORCPT ); Sun, 2 Apr 2023 14:04:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231144AbjDBSEr (ORCPT ); Sun, 2 Apr 2023 14:04:47 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31B4F558B; Sun, 2 Apr 2023 11:04:46 -0700 (PDT) From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1680458683; bh=QOC+hmegC2L3PEWdvDZRUgvKeYyvc+Fv0GYoxoLbGqY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BqjyAbQUgBkgB0MfvVpqVXi1JPSgVjwmYANa2w1mt1+sK3UtNE99tQwAmgjzzFW7y 4z0B0t35r3l8rn/xSeVNgXHuqatgP5wD2RiJbGCr558If0cSae5SdJnmsMQQALMvZl SeXUtBVTKEaFXebItrqyw2vFcIDS7WP+XOuNHBQs= Date: Sun, 02 Apr 2023 18:04:36 +0000 Subject: [PATCH v3 3/4] tools/nolibc: implement fd-based FILE streams MIME-Version: 1.0 Message-Id: <20230328-nolibc-printf-test-v3-3-ddc79f92efd5@weissschuh.net> References: <20230328-nolibc-printf-test-v3-0-ddc79f92efd5@weissschuh.net> In-Reply-To: <20230328-nolibc-printf-test-v3-0-ddc79f92efd5@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1680458682; l=3629; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=QOC+hmegC2L3PEWdvDZRUgvKeYyvc+Fv0GYoxoLbGqY=; b=bt4M+CbIQgzuqN/9lDOZZI80k6Y2pAvGjw7lYMVjY+oBBgyiloL4qOkj+WgQhgWtQCReeLkwf ApJfsxnx0s6D1uMow0XaLiADTMP13R30namU7owoRCYotJJUay7RdAW X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org This enables the usage of the stream APIs with arbitrary filedescriptors. It will be used by a future testcase. Signed-off-by: Thomas Weißschuh --- Willy: This uses intptr_t instead of uintptr_t as proposed because uintptr_t can not be negative. --- tools/include/nolibc/stdio.h | 95 +++++++++++++++++++++++++++++++------------- 1 file changed, 68 insertions(+), 27 deletions(-) diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index 96ac8afc5aee..4add736c07aa 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -21,17 +21,75 @@ #define EOF (-1) #endif -/* just define FILE as a non-empty type */ +/* just define FILE as a non-empty type. The value of the pointer gives + * the FD: FILE=~fd for fd>=0 or NULL for fd<0. This way positive FILE + * are immediately identified as abnormal entries (i.e. possible copies + * of valid pointers to something else). + */ typedef struct FILE { char dummy[1]; } FILE; -/* We define the 3 common stdio files as constant invalid pointers that - * are easily recognized. - */ -static __attribute__((unused)) FILE* const stdin = (FILE*)-3; -static __attribute__((unused)) FILE* const stdout = (FILE*)-2; -static __attribute__((unused)) FILE* const stderr = (FILE*)-1; +static __attribute__((unused)) FILE* const stdin = (FILE*)(intptr_t)~STDIN_FILENO; +static __attribute__((unused)) FILE* const stdout = (FILE*)(intptr_t)~STDOUT_FILENO; +static __attribute__((unused)) FILE* const stderr = (FILE*)(intptr_t)~STDERR_FILENO; + +/* provides a FILE* equivalent of fd. The mode is ignored. */ +static __attribute__((unused)) +FILE *fdopen(int fd, const char *mode __attribute__((unused))) +{ + if (fd < 0) { + SET_ERRNO(EBADF); + return NULL; + } + return (FILE*)(intptr_t)~fd; +} + +/* provides the fd of stream. */ +static __attribute__((unused)) +int fileno(FILE *stream) +{ + intptr_t i = (intptr_t)stream; + + if (i >= 0) { + SET_ERRNO(EBADF); + return -1; + } + return ~i; +} + +/* flush a stream. */ +static __attribute__((unused)) +int fflush(FILE *stream) +{ + intptr_t i = (intptr_t)stream; + + /* NULL is valid here. */ + if (i > 0) { + SET_ERRNO(EBADF); + return -1; + } + + /* Don't do anything, nolibc does not support buffering. */ + return 0; +} + +/* flush a stream. */ +static __attribute__((unused)) +int fclose(FILE *stream) +{ + intptr_t i = (intptr_t)stream; + + if (i >= 0) { + SET_ERRNO(EBADF); + return -1; + } + + if (close(~i)) + return EOF; + + return 0; +} /* getc(), fgetc(), getchar() */ @@ -41,14 +99,8 @@ static __attribute__((unused)) int fgetc(FILE* stream) { unsigned char ch; - int fd; - if (stream < stdin || stream > stderr) - return EOF; - - fd = 3 + (long)stream; - - if (read(fd, &ch, 1) <= 0) + if (read(fileno(stream), &ch, 1) <= 0) return EOF; return ch; } @@ -68,14 +120,8 @@ static __attribute__((unused)) int fputc(int c, FILE* stream) { unsigned char ch = c; - int fd; - - if (stream < stdin || stream > stderr) - return EOF; - - fd = 3 + (long)stream; - if (write(fd, &ch, 1) <= 0) + if (write(fileno(stream), &ch, 1) <= 0) return EOF; return ch; } @@ -96,12 +142,7 @@ static __attribute__((unused)) int _fwrite(const void *buf, size_t size, FILE *stream) { ssize_t ret; - int fd; - - if (stream < stdin || stream > stderr) - return EOF; - - fd = 3 + (long)stream; + int fd = fileno(stream); while (size) { ret = write(fd, buf, size); From patchwork Sun Apr 2 18:04:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13197522 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 640B7C77B62 for ; Sun, 2 Apr 2023 18:04:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231339AbjDBSEs (ORCPT ); Sun, 2 Apr 2023 14:04:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231136AbjDBSEr (ORCPT ); Sun, 2 Apr 2023 14:04:47 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F5DA5255; Sun, 2 Apr 2023 11:04:45 -0700 (PDT) From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1680458683; bh=lRlYUuDp5glflddJvEoeapRiiCbk9usZQ1sjBHNJHWA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hAqtsk1tMBTOcLmQdfShfuClxGMOfQ87C1yjw1nXaohBeAmIZ/e/XxuFfsdy7yO+p OXqzOIh903ka6x+00ab+Iz2eJSzlOzTipUjoo/vQ0DSbbJ3BJgIGarqD0mQTag+73p CKaeLPdhaEvB9qxGbfTqKeI8hzmdfQSmNYAYoOU0= Date: Sun, 02 Apr 2023 18:04:37 +0000 Subject: [PATCH v3 4/4] tools/nolibc: add testcases for vfprintf MIME-Version: 1.0 Message-Id: <20230328-nolibc-printf-test-v3-4-ddc79f92efd5@weissschuh.net> References: <20230328-nolibc-printf-test-v3-0-ddc79f92efd5@weissschuh.net> In-Reply-To: <20230328-nolibc-printf-test-v3-0-ddc79f92efd5@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1680458682; l=3462; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=lRlYUuDp5glflddJvEoeapRiiCbk9usZQ1sjBHNJHWA=; b=r1gaqwcr5bI+JYJYF6F/e7zU/ZbkMtq+8Nx9jeWHBtiCSsdad9o8hV1RBLVCxN8lFZ0Rv2ta+ gv3a94JEvWNBu2sE9onoc7uR2GvxejWHKmk4N4eDNT6RtNdjesRUa4P X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org vfprintf() is complex and so far did not have proper tests. Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/nolibc/nolibc-test.c | 86 ++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 47013b78972e..de943e028933 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -667,6 +668,90 @@ int run_stdlib(int min, int max) return ret; } +#define EXPECT_VFPRINTF(c, expected, fmt, ...) \ + ret += expect_vfprintf(llen, c, expected, fmt, ##__VA_ARGS__) + +static int expect_vfprintf(int llen, size_t c, const char *expected, const char *fmt, ...) +{ + int ret, fd, w, r; + char buf[100]; + FILE *memfile; + va_list args; + + fd = memfd_create("vfprintf", 0); + if (fd == -1) { + pad_spc(llen, 64, "[FAIL]\n"); + return 1; + } + + memfile = fdopen(fd, "w+"); + if (!memfile) { + pad_spc(llen, 64, "[FAIL]\n"); + return 1; + } + + va_start(args, fmt); + w = vfprintf(memfile, fmt, args); + va_end(args); + + if (w != c) { + llen += printf(" written(%d) != %d", w, (int) c); + pad_spc(llen, 64, "[FAIL]\n"); + return 1; + } + + fflush(memfile); + lseek(fd, 0, SEEK_SET); + + r = read(fd, buf, sizeof(buf) - 1); + buf[r] = '\0'; + + fclose(memfile); + + if (r != w) { + llen += printf(" written(%d) != read(%d)", w, r); + pad_spc(llen, 64, "[FAIL]\n"); + return 1; + } + + llen += printf(" \"%s\" = \"%s\"", expected, buf); + ret = strncmp(expected, buf, c); + + pad_spc(llen, 64, ret ? "[FAIL]\n" : " [OK]\n"); + return ret; +} + +static int run_vfprintf(int min, int max) +{ + int test; + int tmp; + int ret = 0; + void *p1, *p2; + + for (test = min; test >= 0 && test <= max; test++) { + int llen = 0; // line length + + /* avoid leaving empty lines below, this will insert holes into + * test numbers. + */ + switch (test + __LINE__ + 1) { + CASE_TEST(empty); EXPECT_VFPRINTF(0, "", ""); break; + CASE_TEST(simple); EXPECT_VFPRINTF(3, "foo", "foo"); break; + CASE_TEST(string); EXPECT_VFPRINTF(3, "foo", "%s", "foo"); break; + CASE_TEST(number); EXPECT_VFPRINTF(4, "1234", "%d", 1234); break; + CASE_TEST(negnumber); EXPECT_VFPRINTF(5, "-1234", "%d", -1234); break; + CASE_TEST(unsigned); EXPECT_VFPRINTF(5, "12345", "%u", 12345); break; + CASE_TEST(char); EXPECT_VFPRINTF(1, "c", "%c", 'c'); break; + CASE_TEST(hex); EXPECT_VFPRINTF(1, "f", "%x", 0xf); break; + CASE_TEST(pointer); EXPECT_VFPRINTF(3, "0x1", "%p", (void *) 0x1); break; + case __LINE__: + return ret; /* must be last */ + /* note: do not set any defaults so as to permit holes above */ + } + } + return ret; +} + static int smash_stack(void) { char buf[100]; @@ -774,6 +859,7 @@ static const struct test test_names[] = { /* add new tests here */ { .name = "syscall", .func = run_syscall }, { .name = "stdlib", .func = run_stdlib }, + { .name = "vfprintf", .func = run_vfprintf }, { .name = "protection", .func = run_protection }, { 0 } };