From 2fdd7f1170253984c1b065ac3a0fc43a31997c05 Mon Sep 17 00:00:00 2001 From: Chiranmoy Bhattacharya Date: Thu, 4 Sep 2025 15:44:19 +0530 Subject: [PATCH v6 3/3] Regression tests for SIMD hex coding --- src/test/regress/expected/hex_coding.out | 63 ++++++++++++++++++++++++ src/test/regress/parallel_schedule | 5 ++ src/test/regress/sql/hex_coding.sql | 39 +++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 src/test/regress/expected/hex_coding.out create mode 100644 src/test/regress/sql/hex_coding.sql diff --git a/src/test/regress/expected/hex_coding.out b/src/test/regress/expected/hex_coding.out new file mode 100644 index 00000000000..e6d78fa4876 --- /dev/null +++ b/src/test/regress/expected/hex_coding.out @@ -0,0 +1,63 @@ +-- +-- tests for hex_encode and hex_decode in encode.c +-- +-- Build table for testing +CREATE TABLE BYTEA_TABLE(data BYTEA); +-- hex_decode is used for inserting into bytea column +-- Set bytea_output to hex so that hex_encode is used and tested +SET bytea_output = 'hex'; +INSERT INTO BYTEA_TABLE VALUES ('\xAB'); +INSERT INTO BYTEA_TABLE VALUES ('\x01ab'); +INSERT INTO BYTEA_TABLE VALUES ('\xDEADC0DE'); +INSERT INTO BYTEA_TABLE VALUES ('\xbaadf00d'); +INSERT INTO BYTEA_TABLE VALUES ('\x C001 c0ffee '); -- hex string with whitespaces +-- errors checking +INSERT INTO BYTEA_TABLE VALUES ('\xbadf00d'); -- odd number of hex digits +ERROR: invalid hexadecimal data: odd number of digits +LINE 1: INSERT INTO BYTEA_TABLE VALUES ('\xbadf00d'); + ^ +INSERT INTO BYTEA_TABLE VALUES ('\xdeadcode'); -- invalid hexadecimal digit: "o" +ERROR: invalid hexadecimal digit: "o" +LINE 1: INSERT INTO BYTEA_TABLE VALUES ('\xdeadcode'); + ^ +INSERT INTO BYTEA_TABLE VALUES ('\xC00LC0FFEE'); -- invalid hexadecimal digit: "L" +ERROR: invalid hexadecimal digit: "L" +LINE 1: INSERT INTO BYTEA_TABLE VALUES ('\xC00LC0FFEE'); + ^ +INSERT INTO BYTEA_TABLE VALUES ('\xC00LC*DE'); -- invalid hexadecimal digit: "*" +ERROR: invalid hexadecimal digit: "L" +LINE 1: INSERT INTO BYTEA_TABLE VALUES ('\xC00LC*DE'); + ^ +INSERT INTO BYTEA_TABLE VALUES ('\xbad f00d'); -- invalid hexadecimal digit: " " +ERROR: invalid hexadecimal digit: " " +LINE 1: INSERT INTO BYTEA_TABLE VALUES ('\xbad f00d'); + ^ +-- long hex strings to test SIMD implementation +INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 8))::bytea; +INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 8) || repeat('baadf00d', 8))::bytea; +INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 8) || ' ' || repeat('baad f00d', 8))::bytea; -- hex string with whitespaces +-- errors checking for SIMD implementation +INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 4) || 'badf00d' || repeat('DEADC0DE', 4))::bytea; -- odd number of hex digits +ERROR: invalid hexadecimal data: odd number of digits +INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 4) || 'baadfood'|| repeat('DEADC0DE', 4))::bytea; -- invalid hexadecimal digit: "o" +ERROR: invalid hexadecimal digit: "o" +INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 4) || 'C00LC0FFEE' || repeat('DEADC0DE', 4))::bytea; -- invalid hexadecimal digit: "L" +ERROR: invalid hexadecimal digit: "L" +INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 8) || 'C00LC*DE' || repeat('DEADC0DE', 4))::bytea; -- invalid hexadecimal digit: "*" +ERROR: invalid hexadecimal digit: "L" +INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 8) || 'bad f00d' || repeat('DEADC0DE', 4))::bytea; -- invalid hexadecimal digit: " " +ERROR: invalid hexadecimal digit: " " +SELECT encode(data, 'hex') FROM BYTEA_TABLE; + encode +---------------------------------------------------------------------------------------------------------------------------------- + ab + 01ab + deadc0de + baadf00d + c001c0ffee + deadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0de + deadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0debaadf00dbaadf00dbaadf00dbaadf00dbaadf00dbaadf00dbaadf00dbaadf00d + deadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0debaadf00dbaadf00dbaadf00dbaadf00dbaadf00dbaadf00dbaadf00dbaadf00d +(8 rows) + +DROP TABLE BYTEA_TABLE; diff --git a/src/test/regress/parallel_schedule b/src/test/regress/parallel_schedule index fbffc67ae60..876a3988ed0 100644 --- a/src/test/regress/parallel_schedule +++ b/src/test/regress/parallel_schedule @@ -109,6 +109,11 @@ test: select_views portals_p2 foreign_key cluster dependency guc bitmapops combo # ---------- test: json jsonb json_encoding jsonpath jsonpath_encoding jsonb_jsonpath sqljson sqljson_queryfuncs sqljson_jsontable +# ---------- +# Another group of parallel tests for hex encode/decode +# ---------- +test: hex_coding + # ---------- # Another group of parallel tests # with depends on create_misc diff --git a/src/test/regress/sql/hex_coding.sql b/src/test/regress/sql/hex_coding.sql new file mode 100644 index 00000000000..97c51b62e90 --- /dev/null +++ b/src/test/regress/sql/hex_coding.sql @@ -0,0 +1,39 @@ +-- +-- tests for hex_encode and hex_decode in encode.c +-- + +-- Build table for testing +CREATE TABLE BYTEA_TABLE(data BYTEA); + +-- hex_decode is used for inserting into bytea column +-- Set bytea_output to hex so that hex_encode is used and tested +SET bytea_output = 'hex'; + +INSERT INTO BYTEA_TABLE VALUES ('\xAB'); +INSERT INTO BYTEA_TABLE VALUES ('\x01ab'); +INSERT INTO BYTEA_TABLE VALUES ('\xDEADC0DE'); +INSERT INTO BYTEA_TABLE VALUES ('\xbaadf00d'); +INSERT INTO BYTEA_TABLE VALUES ('\x C001 c0ffee '); -- hex string with whitespaces + +-- errors checking +INSERT INTO BYTEA_TABLE VALUES ('\xbadf00d'); -- odd number of hex digits +INSERT INTO BYTEA_TABLE VALUES ('\xdeadcode'); -- invalid hexadecimal digit: "o" +INSERT INTO BYTEA_TABLE VALUES ('\xC00LC0FFEE'); -- invalid hexadecimal digit: "L" +INSERT INTO BYTEA_TABLE VALUES ('\xC00LC*DE'); -- invalid hexadecimal digit: "*" +INSERT INTO BYTEA_TABLE VALUES ('\xbad f00d'); -- invalid hexadecimal digit: " " + +-- long hex strings to test SIMD implementation +INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 8))::bytea; +INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 8) || repeat('baadf00d', 8))::bytea; +INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 8) || ' ' || repeat('baad f00d', 8))::bytea; -- hex string with whitespaces + +-- errors checking for SIMD implementation +INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 4) || 'badf00d' || repeat('DEADC0DE', 4))::bytea; -- odd number of hex digits +INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 4) || 'baadfood'|| repeat('DEADC0DE', 4))::bytea; -- invalid hexadecimal digit: "o" +INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 4) || 'C00LC0FFEE' || repeat('DEADC0DE', 4))::bytea; -- invalid hexadecimal digit: "L" +INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 8) || 'C00LC*DE' || repeat('DEADC0DE', 4))::bytea; -- invalid hexadecimal digit: "*" +INSERT INTO BYTEA_TABLE SELECT ('\x' || repeat('DEADC0DE', 8) || 'bad f00d' || repeat('DEADC0DE', 4))::bytea; -- invalid hexadecimal digit: " " + +SELECT encode(data, 'hex') FROM BYTEA_TABLE; + +DROP TABLE BYTEA_TABLE; -- 2.34.1