From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: util-linux-owner@vger.kernel.org Received: from mx1.redhat.com ([209.132.183.28]:56203 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753391AbbJPJS5 (ORCPT ); Fri, 16 Oct 2015 05:18:57 -0400 Date: Fri, 16 Oct 2015 11:18:55 +0200 From: Karel Zak To: Sami Kerola Cc: util-linux@vger.kernel.org Subject: Re: [PATCH 3/8] libuuid: add uuid_generate_file() function Message-ID: <20151016091855.GA2990@ws.net.home> References: <1444735754-18976-1-git-send-email-kerolasa@iki.fi> <1444735754-18976-4-git-send-email-kerolasa@iki.fi> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii In-Reply-To: <1444735754-18976-4-git-send-email-kerolasa@iki.fi> Sender: util-linux-owner@vger.kernel.org List-ID: On Tue, Oct 13, 2015 at 12:29:09PM +0100, Sami Kerola wrote: > The uuid_generate_file() allows generating UUID using input file, and thus > leading to stable output. Purpose of this function is to have a facility > that allows tests to be wrote. Well, if you want to generate non-random stuff then it seems enough to modify __uuid_generate_random() and __uuid_generate_time() to return non-random stuff on -DLIBUUID_ENABLE_TEST. The problem is that things like get_clock(), pack, unpack, parse and unparse functions will be still untested. What about to support random UUIDs in our tests and modify the __uuid_generate functions to copy unpacked raw result to any file? Something like: int __uuid_generate_time(uuid_t out, int *num) { ... generate struct uu as usually ... #ifdef LIBUUID_ENABLE_TEST ts_path = genenv("LIBUUID_TEST_PATH"); if (ts_path) write_raw_uuid(uu, ts_path); #endif return ret; } where write_uraw_uuid() is function to write struct uuid to the /. Then we can write test_uuid --random|--time this program 1/ ask libuuid for a new UUID 2/ unparse and unpack to get struct uuid 3/ write struct uuid to the by write_uraw_uuid() and in the shell script we can by diff -u compare $LIBUUID_TEST_PATH/ with . The is also possible to use to check if UUID has been really generated by uuidd. (It would be nice to have two sub-tests, one with uuidd and one without uuid.) Note that uuid_unpack() is not exported by library API, so you have to link libuuid/src/unpack.c directly to the test_uuid.c. (It would be also possible to analyze struct uuid from $LIBUUID_TEST_PATH to make sure that for example get_node_id() works as expected, etc... but this is not urgent.) Karel -- Karel Zak http://karelzak.blogspot.com