[flac-dev] Permit running tests as root

Christian Weisgerber
Tue, 27 Sep 2022 20:38:22 -0000

Some people build software and run the regression tests as root.
(Possibly in some restricted environment.)

<packager hat>I've been asked to make sure this works.</>

Unfortunately, the FLAC tests currently error out in two places if
run as root:

===> test_libFLAC
++++++ testing level 1 interface
simple iterator on read-only file
generating FLAC file for test
        testing 'metadata.flac'... 0... 1... 2... content... PASSED
is writable = 1
ERROR: iterator claims file is writable when tester thinks it should not be; are
you running as root?

===> test_libFLAC++
++++++ testing level 1 interface
simple iterator on read-only file
generating FLAC file for test
          testing 'metadata.flac'... 0... 1... 2... content... PASSED
is writable = 1
ERROR: iterator claims file is writable when tester thinks it should not be; are
you running as root?


Can we skip that test when root?

Something along the lines of the following...?

--- src/test_libFLAC++/metadata_manip.cpp.orig	2022-09-27 20:22:19 UTC
+++ src/test_libFLAC++/metadata_manip.cpp
@@ -818,13 +818,16 @@ static bool test_level_1_()

 	printf("\n\n++++++ testing level 1 interface\n");

+	if(!generate_file_(/*include_extras=*/false, /*is_ogg=*/false))
+		return false;
+
+	if (getuid() == 0)
+		goto next;
+
 	/************************************************************/
 	{
 	printf("simple iterator on read-only file\n");

-	if(!generate_file_(/*include_extras=*/false, /*is_ogg=*/false))
-		return false;
-
 	if(!change_stats_(flacfilename(/*is_ogg=*/false), /*read_only=*/true))
 		return false;

@@ -912,6 +915,7 @@ static bool test_level_1_()
 	}

 	/************************************************************/
+next:
 	{
 	printf("simple iterator on writable file\n");

--- src/test_libFLAC/metadata_manip.c.orig	2022-09-27 20:17:48 UTC
+++ src/test_libFLAC/metadata_manip.c
@@ -786,11 +786,14 @@ static FLAC__bool test_level_1_(void)

 	/************************************************************/

-	printf("simple iterator on read-only file\n");
-
 	if(!generate_file_(/*include_extras=*/false, /*is_ogg=*/false))
 		return false;

+	if (getuid() == 0)
+		goto next;
+
+	printf("simple iterator on read-only file\n");
+
 	if(!change_stats_(flacfilename(/*is_ogg=*/false), /*read_only=*/true))
 		return false;

@@ -874,7 +877,7 @@ static FLAC__bool test_level_1_(void)
 	FLAC__metadata_simple_iterator_delete(iterator);

 	/************************************************************/
-
+next:
 	printf("simple iterator on writable file\n");

 	if(!change_stats_(flacfilename(/*is_ogg=*/false), /*read-only=*/false))

--
Christian "naddy" Weisgerber                          naddy at
mips.inka.de