From patchwork Wed Sep 26 23:15:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 29557 Received: (qmail 37030 invoked by alias); 26 Sep 2018 23:16:16 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 36465 invoked by uid 89); 26 Sep 2018 23:15:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, TIME_LIMIT_EXCEEDED autolearn=unavailable version=3.3.2 spammy=1, 89 X-HELO: gateway24.websitewelcome.com Received: from gateway24.websitewelcome.com (HELO gateway24.websitewelcome.com) (192.185.50.84) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 26 Sep 2018 23:15:04 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway24.websitewelcome.com (Postfix) with ESMTP id B9A7A138BD for ; Wed, 26 Sep 2018 18:15:02 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 5J1KgaIlKPvAd5J1KgSIcv; Wed, 26 Sep 2018 18:15:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=OQqhOncpGCsf1DK49jjENZ7iigexgZfQ8AUuqJ+KSY4=; b=mA6du8WrikVrEd02a7039QWHUT lHTMT8ds//+sPfwtKAufQeT4uJgCaPSE1kBpz44n7Uha2vnux0M2jrSgT2QNIhwtG5hh7kRWy4R6Z R6HwdalayQtrI2ybv/hWK7js0; Received: from 97-122-190-66.hlrn.qwest.net ([97.122.190.66]:48536 helo=bapiya) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1g5J1K-003lO4-FQ; Wed, 26 Sep 2018 18:15:02 -0500 From: Tom Tromey To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [RFC 3/6] Move mkdir_recursive to common/filestuff.c References: <20180926111130.18956-1-tom@tromey.com> <20180926111130.18956-4-tom@tromey.com> <877ej7kixp.fsf@tromey.com> Date: Wed, 26 Sep 2018 17:15:01 -0600 In-Reply-To: <877ej7kixp.fsf@tromey.com> (Tom Tromey's message of "Wed, 26 Sep 2018 16:11:46 -0600") Message-ID: <8736tvkg0a.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.50 (gnu/linux) MIME-Version: 1.0 >>>>> "Tom" == Tom Tromey writes: Tom> I forgot to git add this file. Tom> I'll send it soon. This is just the missing part of this patch. Tom commit 7c8093b561466131da4fd9ad30d93b3640615426 Author: Tom Tromey Date: Wed Sep 26 16:16:55 2018 -0600 add the test diff --git a/gdb/unittests/mkdir-recursive-selftests.c b/gdb/unittests/mkdir-recursive-selftests.c new file mode 100644 index 0000000000..d501f8e081 --- /dev/null +++ b/gdb/unittests/mkdir-recursive-selftests.c @@ -0,0 +1,89 @@ +/* Self tests for scoped_fd for GDB, the GNU debugger. + + Copyright (C) 2018 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "defs.h" + +#include "common/filestuff.h" +#include "selftest.h" + +namespace selftests { +namespace mkdir_recursive { + +/* Try to create DIR using mkdir_recursive and make sure it exists. */ + +static bool +create_dir_and_check (const char *dir) +{ + ::mkdir_recursive (dir); + + struct stat st; + if (stat (dir, &st) != 0) + perror_with_name (("stat")); + + return (st.st_mode & S_IFDIR) != 0; +} + +/* Test mkdir_recursive. */ + +static void +test () +{ + char base[] = "/tmp/gdb-selftests-XXXXXX"; + + if (mkdtemp (base) == NULL) + perror_with_name (("mkdtemp")); + + /* Try not to leave leftover directories. */ + struct cleanup_dirs { + cleanup_dirs (const char *base) + : m_base (base) + {} + + ~cleanup_dirs () { + rmdir (string_printf ("%s/a/b/c/d/e", m_base).c_str ()); + rmdir (string_printf ("%s/a/b/c/d", m_base).c_str ()); + rmdir (string_printf ("%s/a/b/c", m_base).c_str ()); + rmdir (string_printf ("%s/a/b", m_base).c_str ()); + rmdir (string_printf ("%s/a", m_base).c_str ()); + rmdir (m_base); + } + + private: + const char *m_base; + } cleanup_dirs (base); + + std::string dir = string_printf ("%s/a/b", base); + SELF_CHECK (create_dir_and_check (dir.c_str ())); + + dir = string_printf ("%s/a/b/c//d/e/", base); + SELF_CHECK (create_dir_and_check (dir.c_str ())); +} + +} +} + +void +_initialize_mkdir_recursive_selftests () +{ +#if defined (HAVE_MKDTEMP) + selftests::register_test ("mkdir_recursive", + selftests::mkdir_recursive::test); +#endif +} +