Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp25940568rwd; Mon, 3 Jul 2023 03:14:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4RjOYPVTgM0QQVsz4KcuaNLpJJ7dkJOrL27bs3nskak+QfG+1MJ17xVka7HT4rWCida9b9 X-Received: by 2002:a05:6a20:5486:b0:12c:a8e9:7bf6 with SMTP id i6-20020a056a20548600b0012ca8e97bf6mr14708805pzk.10.1688379299446; Mon, 03 Jul 2023 03:14:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688379299; cv=none; d=google.com; s=arc-20160816; b=Y7sL5o4/gbPtsNuqbwW1gIEBf3tt6foeJhP8A3ofH5Gvzybg8vN7DtgS/rvLr/M2jW 2TtqkL2TsASNZLB0zOIfWC4sMi72yqJi4UItDg7SovCI2wYDEs9CLxdjUdP+35sUgg8h l4klEp7mGyZbewjgJJCHCnTg/e/3TRdJEIFlZzYGOs9ay4edmf+O8rVW6QlKU8eMNo9Q 3cqYhN+x/7NSrKPSBds8UgeQB1HGJykR9FwSTU16SN9UJM4zQt4YlaSRR8UZNjAxh5Fb V/YOb99rtoCeQWIIOoPuSPwZxyoqN6bIumal4L46Fvfn8r+lB/JVmr+wWEObzUsmNQcy QRDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=BoCvW/e6QT4pO4L4I3xuuS52hYbNhS8BvsucgO9szCI=; fh=TP1doRzy/JQVoSwjwn+TY25lGT2rA5CtU2bwleSknKI=; b=K6H5ArEIYEGXPSfcqRe4PYTBk6uixc6lyyAtFfFHZSzEaw9eENSX71SUzFK73mnlkT OQimFGWED4QP2iEQKWZz+/4qFcX1i/25q2WVQ65PnKLn4LVgIK2vqyK5uEYTrd2/X9t9 2Rcpz8EaeHVr42NOm32NYbEa8TXeHJTV1atkbxQJB4KapKfYk2GwoqyYNPXtH5J3K04k anihaFeneKHXTScijzCf9j48TbNJw/FjjcZbgZrk7YJDqUGPIUb6D2cvwpkOCA9wKUWj pcG3dsmnEU9REBABcnV2U/Qg5w+FVDfgcDC4IwH8QCEnkFHCzvLp8Ex/7WUx3FGDEEIH vkig== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a634744000000b00547b25ea099si18470656pgk.682.2023.07.03.03.14.45; Mon, 03 Jul 2023 03:14:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231784AbjGCKAc (ORCPT + 99 others); Mon, 3 Jul 2023 06:00:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231781AbjGCKAP (ORCPT ); Mon, 3 Jul 2023 06:00:15 -0400 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 282241FDE; Mon, 3 Jul 2023 02:56:43 -0700 (PDT) Received: (from willy@localhost) by mail.home.local (8.17.1/8.17.1/Submit) id 3639uRd9023860; Mon, 3 Jul 2023 11:56:27 +0200 Date: Mon, 3 Jul 2023 11:56:27 +0200 From: Willy Tarreau To: Zhangjin Wu Cc: arnd@arndb.de, david.laight@aculab.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, linux@weissschuh.net, thomas@t-8ch.de Subject: Re: [PATCH v5 14/14] selftests/nolibc: add mmap and munmap test cases Message-ID: References: <20230703080647.491363-1-falcon@tinylab.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230703080647.491363-1-falcon@tinylab.org> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 03, 2023 at 04:06:47PM +0800, Zhangjin Wu wrote: > > > /* get absolute path of myself, nolibc has no realpath() currently */ > > > #ifndef NOLIBC > > > realpath(argv[0], exe); > > > #else > > > /* assume absolute path has no "./" */ > > > if (strncmp(argv[0], "./", 2) != 0) > > > strncat(exe, argv[0], strlen(argv[0]) + 1); > > > else { > > > pwd = getenv("PWD"); > > > /* skip the ending '\0' */ > > > strncat(exe, getenv("PWD"), strlen(pwd)); > > > /* skip the first '.' */ > > > strncat(exe, argv[0] + 1, strlen(argv[0])); > > > } > > > #endif > > > > No, please, not like this. Just copy argv[0] (the pointer not the > > contents) and you're fine: > > > > static const char *argv0; > > > > int main(int argc, char **argv, char **envp) > > { > > argv0 = argv[0]; > > ... > > } > > > > Nothing more, nothing less. Your program will always have its correct > > path when being called unless someone purposely forces it to something > > different, which is not our concern at all since this is a test program. > > And I'd rather call it "argv0" which exactly tells us what it contains > > than "exe" which can be misleading for that precise reason. > > > > Yeah, locally, I just used a global argv0 pointer directly, but > chroot_exe("./nolibc-test") not work when run 'libc-test' in host > system, that is why I tried to get an absolute path ;-) > > CASE_TEST(chroot_exe); EXPECT_SYSER(1, chroot(exe), -1, ENOTDIR); break; > > --> > > 19 chroot_exe = -1 ENOENT != (-1 ENOTDIR) [FAIL] Then we have a problem somewhere else and the test should be debugger instead. Are you sure there isn't a successful chdir() test before it for example, that would change the directory ? If so maybe we just need to save the current dir before calling it and restore it later. > I removed the "proc ?" check manually to test if it also work with > CONFIG_PROC_FS=n. it doesn't work, without absolute path, we need to add > the ENOENT errno back to the errno check list. Same as above. > I'm not sure if the other syscalls require an absolute path, so, the > realpath() is called in this proposed method. No, please do not overengineer tests. That's only hiding the dust under the carpet and people adding more tests later that will randomly fail will have a very hard time trying to figure what's happening under the hood. If a test doesn't work as expected, we must not try to work around it, but arrange to fix it. Thanks, Willy