Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp26074538rwd; Mon, 3 Jul 2023 05:14:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5BnAPFLGN6H8PwRTPpWu0bpOZTipiaAJjO+/VuB6sXfrL5T+uXJoIwo+cK+/nffSVhNog7 X-Received: by 2002:a05:6871:c15:b0:18e:af01:ad93 with SMTP id ve21-20020a0568710c1500b0018eaf01ad93mr9885209oab.58.1688386480398; Mon, 03 Jul 2023 05:14:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688386480; cv=none; d=google.com; s=arc-20160816; b=UIi05Ip+dIJU6gHN+fgBf1E6rpchbGYn/eXKXKJmECDfM2iZZUCw6irqYnha/HKqo+ yuXVoyNcg/mNkDryvL/lz31VIIuzY7QabhkKLT3jVa3zQnpxDymfM5Eg5FDldkqVcA3D HGQ54NBKDhyjYSnm8wej5G19PmXKzlMzxfnOugG2V2P0NaqSylb2ZCNTafZ0u037T8tg Ymf7RxhLYyQYKYsinQ/RY956xEQ5UrQm3Oqqb7Ld1uFeYAccUvwSujTOobYeVhByq9bE AXb4bPbOq0x5FS8TDTpI9dSn1U0BtNXYZH1mbX0WzGEYeg48TeSXfhnrv0mXqYHpHQR7 cmow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=pPLgHH7UCuRR0PJLnyOA3BVsZQbcF0HbCOsA0IDsRHI=; fh=m7txAxT0Z9hMAqPgSGN0O36TdJLf6qrKfc7dhOTuVFA=; b=UkpZ8pwq/P0QFeGl3ajkwfk8zl0YEcFgo35BAEH0t60Ia/gIOGFUq65WDH6PTwrCMO UfULG1LzI8eGU5KH8nzwSY403PpznvCX6JNZcwPmmyJzM9GWW4tOQKp1xaMe2Pxd4zVp YtICxD9S2Rx4x6tnDf23PNqPJ/keOpAhvBjpBsiiS+dn/LRZvzH6Ieb1WXWcZeI/RgDn sZLcLpyfeGjNsb5VRzSKqO9CcAewODPUOkgy+Aibut3LBILb72xAO6Bevy/XM2IFIfs+ ukuSUsWsZjSTQqZUdeZvKnEGzQUhp8i5b7G9p72TWd2t1SNnYyV6K9We/iusn0u/wd1e QIPQ== 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 k191-20020a6384c8000000b0055ba60a3301si2094485pgd.295.2023.07.03.05.14.27; Mon, 03 Jul 2023 05:14:40 -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 S230357AbjGCLY0 (ORCPT + 99 others); Mon, 3 Jul 2023 07:24:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229960AbjGCLYZ (ORCPT ); Mon, 3 Jul 2023 07:24:25 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F278CC1; Mon, 3 Jul 2023 04:24:22 -0700 (PDT) X-QQ-mid: bizesmtp81t1688383446t1op3cnl Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 03 Jul 2023 19:24:05 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: cbck7jzG4wYC8mah2/jqlcxJTdWqDIK9P0UT4RX2Zum2vuyXXC6GWwjeRgmzi 5/ELDpDe6XvNbfUpTU0H8qffvoj/1wliAi3LfhVM+yvinfG5Yq2cc9wgZGr7jh3+q2tf7RO AVP4PAzEebTO5WBTKxnDJfl8edKAsiD56sJ7Mdl6KYgMye1rSVWgCU14evKkNZCml/bi14Q Sdy6bwd5XLt5b02oNBAone6RkiBz9wx7752eQed4TmgXmfPC6GQzVYaHFX+hc2IbYauTJpj k7ulh4XxvMPKqZAqj6EYHYBZo3GgI5uf7R+tKfcGfYV4yCGEeSW2k2rUFnsRkP95SaDkqSl 61di5Pu28vy0V093/Gb0cHaV39BnMJpsgWjsf5ksaoxSxW3lno= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 8141555401561398156 From: Zhangjin Wu To: w@1wt.eu Cc: arnd@arndb.de, david.laight@aculab.com, falcon@tinylab.org, 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 Date: Mon, 3 Jul 2023 19:24:04 +0800 Message-Id: <20230703112404.496996-1-falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,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. > Yes, as Thomas pointed out, the chdir test cases changed current directory to "/" just before chroot_exe(), so, restore it with chdir(getenv("PWD")) solves the issue. > > 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. That's right, thanks. Best regards, Zhangjin > > Thanks, > Willy