Re: [PATCH v12 2/3] selftests: tdx: Test TDX attestation GetReport support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 9/8/22 7:16 AM, Wander Lairson Costa wrote:
> You can unconditionally define print_array_hex, and
> use `if (DEBUG)` instead of #ifdef `DEBUG here`. The compiler
> will get rid of the unused code when DEBUG is not defined
> as expected, but you get the parser to validate it
> independent of the definition of DEBUG.

To avoid #ifdef DEBUG in multiple places, we can try following
change. Let me know your comments.

--- a/tools/testing/selftests/tdx/tdx_attest_test.c

+++ b/tools/testing/selftests/tdx/tdx_attest_test.c

@@ -21,6 +21,14 @@

 #define HEX_DUMP_SIZE  8

 #define __packed       __attribute__((packed))

 

+static inline int _no_printf(const char *format, ...) { return 0; }

+

+#ifdef DEBUG

+#define pr_debug(...) printf(__VA_ARGS__)

+#else

+#define pr_debug(...) _no_printf(__VA_ARGS__)

+#endif

+

 /*

  * Trusted Execution Environment (TEE) report (TDREPORT_STRUCT) type,

  * sub type and version. More details can be found in TDX v1.0 Module

@@ -90,7 +98,6 @@ struct tdreport {

        struct td_info tdinfo;

 }  __packed;

 

-#ifdef DEBUG

 static void print_array_hex(const char *title, const char *prefix_str,

                const void *buf, int len)

 {

@@ -100,17 +107,16 @@ static void print_array_hex(const char *title, const char *prefix_str,

        if (!len || !buf)

                return;

 

-       printf("\t\t%s", title);

+       pr_debug("\t\t%s", title);

 

        for (i = 0; i < len; i++) {

                if (!(i % rowsize))

-                       printf("\n%s%.8x:", prefix_str, i);

-               printf(" %.2x", ptr[i]);

+                       pr_debug("\n%s%.8x:", prefix_str, i);

+               pr_debug(" %.2x", ptr[i]);

        }

 

-       printf("\n");

+       pr_debug("\n");

 }

-#endif

 

 TEST(verify_report)

 {

@@ -139,13 +145,11 @@ TEST(verify_report)

        /* Get TDREPORT */

        ASSERT_EQ(0, ioctl(devfd, TDX_CMD_GET_REPORT, &req));

 

-#ifdef DEBUG

        print_array_hex("\n\t\tTDX report data\n", "",

                        reportdata, sizeof(reportdata));

 

        print_array_hex("\n\t\tTDX tdreport data\n", "",

                        &tdreport, sizeof(tdreport));

-#endif

 

        /* Make sure TDREPORT data includes the REPORTDATA passed */

        ASSERT_EQ(0, memcmp(&tdreport.reportmac.reportdata[0],



-- 
Sathyanarayanan Kuppuswamy
Linux Kernel Developer



[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux