summaryrefslogtreecommitdiff
path: root/contrib/uuid-ossp
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2014-05-28 23:15:51 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2014-05-28 23:15:51 -0400
commit25dd07e0f6ba1aef0a6802474112b5bcce621ea4 (patch)
tree70fe3673b05e18b57ed5a91d55e0062bc5f28b7f /contrib/uuid-ossp
parent71ed8b3ca76cd720f4013c3c20f0d2706583ab9a (diff)
downloadpostgresql-25dd07e0f6ba1aef0a6802474112b5bcce621ea4.tar.gz
Fix uuid-ossp regression tests based on buildfarm feedback.
The previous version of these tests expected uuid_generate_v1() to always emit MAC addresses with the local-admin and multicast address bits zero. However, several of the buildfarm critters are reporting values with the local-admin bit set. (Perhaps they're running inside VMs or jails.) And a couple are reporting values with the multicast bit set, probably meaning that the UUID library couldn't read the system MAC address. Also, it emerges that if OSSP UUID can't read the system MAC address, it falls back to V1MC behavior wherein the whole node field gets randomized each time, breaking the test that expected the node field to remain stable in V1 output. (It looks like e2fs doesn't behave that way, though.) It's not entirely clear why we can't get a system MAC address, since the buildfarm scripts would not work without internet access. Nonetheless, the regression tests had better cope with the case, so adjust the tests to expect these behaviors.
Diffstat (limited to 'contrib/uuid-ossp')
-rw-r--r--contrib/uuid-ossp/expected/uuid_ossp.out46
-rw-r--r--contrib/uuid-ossp/sql/uuid_ossp.sql32
2 files changed, 56 insertions, 22 deletions
diff --git a/contrib/uuid-ossp/expected/uuid_ossp.out b/contrib/uuid-ossp/expected/uuid_ossp.out
index fe3e325992..409c885c33 100644
--- a/contrib/uuid-ossp/expected/uuid_ossp.out
+++ b/contrib/uuid-ossp/expected/uuid_ossp.out
@@ -42,26 +42,35 @@ LANGUAGE SQL STRICT IMMUTABLE;
CREATE FUNCTION uuid_reserved_bits(uuid) RETURNS varbit AS
$$ SELECT ('x' || substr($1::text, 20, 2))::bit(8) & '11000000' $$
LANGUAGE SQL STRICT IMMUTABLE;
-CREATE FUNCTION uuid_multicast_bits(uuid) RETURNS varbit AS
-$$ SELECT ('x' || substr($1::text, 25, 2))::bit(8) & '00000011' $$
+CREATE FUNCTION uuid_multicast_bit(uuid) RETURNS bool AS
+$$ SELECT (('x' || substr($1::text, 25, 2))::bit(8) & '00000001') != '00000000' $$
+LANGUAGE SQL STRICT IMMUTABLE;
+CREATE FUNCTION uuid_local_admin_bit(uuid) RETURNS bool AS
+$$ SELECT (('x' || substr($1::text, 25, 2))::bit(8) & '00000010') != '00000000' $$
LANGUAGE SQL STRICT IMMUTABLE;
CREATE FUNCTION uuid_node(uuid) RETURNS text AS
$$ SELECT substr($1::text, 25) $$
LANGUAGE SQL STRICT IMMUTABLE;
+-- Ideally, the multicast bit would never be set in V1 output, but the
+-- UUID library may fall back to MC if it can't get the system MAC address.
+-- Also, the local-admin bit might be set (if so, we're probably inside a VM).
+-- So we can't test either bit here.
SELECT uuid_version_bits(uuid_generate_v1()),
- uuid_reserved_bits(uuid_generate_v1()),
- uuid_multicast_bits(uuid_generate_v1());
- uuid_version_bits | uuid_reserved_bits | uuid_multicast_bits
--------------------+--------------------+---------------------
- 00010000 | 10000000 | 00000000
+ uuid_reserved_bits(uuid_generate_v1());
+ uuid_version_bits | uuid_reserved_bits
+-------------------+--------------------
+ 00010000 | 10000000
(1 row)
+-- Although RFC 4122 only requires the multicast bit to be set in V1MC style
+-- UUIDs, our implementation always sets the local-admin bit as well.
SELECT uuid_version_bits(uuid_generate_v1mc()),
uuid_reserved_bits(uuid_generate_v1mc()),
- uuid_multicast_bits(uuid_generate_v1mc());
- uuid_version_bits | uuid_reserved_bits | uuid_multicast_bits
--------------------+--------------------+---------------------
- 00010000 | 10000000 | 00000011
+ uuid_multicast_bit(uuid_generate_v1mc()),
+ uuid_local_admin_bit(uuid_generate_v1mc());
+ uuid_version_bits | uuid_reserved_bits | uuid_multicast_bit | uuid_local_admin_bit
+-------------------+--------------------+--------------------+----------------------
+ 00010000 | 10000000 | t | t
(1 row)
-- timestamp+clock sequence should be monotonic increasing in v1
@@ -77,13 +86,20 @@ SELECT uuid_timestamp_bits(uuid_generate_v1mc()) < uuid_timestamp_bits(uuid_gene
t
(1 row)
--- node should be stable in v1, but not v1mc
-SELECT uuid_node(uuid_generate_v1()) = uuid_node(uuid_generate_v1());
- ?column?
-----------
+-- Ideally, the node value is stable in V1 addresses, but OSSP UUID
+-- falls back to V1MC behavior if it can't get the system MAC address.
+SELECT CASE WHEN uuid_multicast_bit(uuid_generate_v1()) AND
+ uuid_local_admin_bit(uuid_generate_v1()) THEN
+ true -- punt, no test
+ ELSE
+ uuid_node(uuid_generate_v1()) = uuid_node(uuid_generate_v1())
+ END;
+ case
+------
t
(1 row)
+-- In any case, V1MC node addresses should be random.
SELECT uuid_node(uuid_generate_v1()) <> uuid_node(uuid_generate_v1mc());
?column?
----------
diff --git a/contrib/uuid-ossp/sql/uuid_ossp.sql b/contrib/uuid-ossp/sql/uuid_ossp.sql
index 3b1fa24bc6..b4237df884 100644
--- a/contrib/uuid-ossp/sql/uuid_ossp.sql
+++ b/contrib/uuid-ossp/sql/uuid_ossp.sql
@@ -23,28 +23,46 @@ CREATE FUNCTION uuid_reserved_bits(uuid) RETURNS varbit AS
$$ SELECT ('x' || substr($1::text, 20, 2))::bit(8) & '11000000' $$
LANGUAGE SQL STRICT IMMUTABLE;
-CREATE FUNCTION uuid_multicast_bits(uuid) RETURNS varbit AS
-$$ SELECT ('x' || substr($1::text, 25, 2))::bit(8) & '00000011' $$
+CREATE FUNCTION uuid_multicast_bit(uuid) RETURNS bool AS
+$$ SELECT (('x' || substr($1::text, 25, 2))::bit(8) & '00000001') != '00000000' $$
+LANGUAGE SQL STRICT IMMUTABLE;
+
+CREATE FUNCTION uuid_local_admin_bit(uuid) RETURNS bool AS
+$$ SELECT (('x' || substr($1::text, 25, 2))::bit(8) & '00000010') != '00000000' $$
LANGUAGE SQL STRICT IMMUTABLE;
CREATE FUNCTION uuid_node(uuid) RETURNS text AS
$$ SELECT substr($1::text, 25) $$
LANGUAGE SQL STRICT IMMUTABLE;
+-- Ideally, the multicast bit would never be set in V1 output, but the
+-- UUID library may fall back to MC if it can't get the system MAC address.
+-- Also, the local-admin bit might be set (if so, we're probably inside a VM).
+-- So we can't test either bit here.
SELECT uuid_version_bits(uuid_generate_v1()),
- uuid_reserved_bits(uuid_generate_v1()),
- uuid_multicast_bits(uuid_generate_v1());
+ uuid_reserved_bits(uuid_generate_v1());
+-- Although RFC 4122 only requires the multicast bit to be set in V1MC style
+-- UUIDs, our implementation always sets the local-admin bit as well.
SELECT uuid_version_bits(uuid_generate_v1mc()),
uuid_reserved_bits(uuid_generate_v1mc()),
- uuid_multicast_bits(uuid_generate_v1mc());
+ uuid_multicast_bit(uuid_generate_v1mc()),
+ uuid_local_admin_bit(uuid_generate_v1mc());
-- timestamp+clock sequence should be monotonic increasing in v1
SELECT uuid_timestamp_bits(uuid_generate_v1()) < uuid_timestamp_bits(uuid_generate_v1());
SELECT uuid_timestamp_bits(uuid_generate_v1mc()) < uuid_timestamp_bits(uuid_generate_v1mc());
--- node should be stable in v1, but not v1mc
-SELECT uuid_node(uuid_generate_v1()) = uuid_node(uuid_generate_v1());
+-- Ideally, the node value is stable in V1 addresses, but OSSP UUID
+-- falls back to V1MC behavior if it can't get the system MAC address.
+SELECT CASE WHEN uuid_multicast_bit(uuid_generate_v1()) AND
+ uuid_local_admin_bit(uuid_generate_v1()) THEN
+ true -- punt, no test
+ ELSE
+ uuid_node(uuid_generate_v1()) = uuid_node(uuid_generate_v1())
+ END;
+
+-- In any case, V1MC node addresses should be random.
SELECT uuid_node(uuid_generate_v1()) <> uuid_node(uuid_generate_v1mc());
SELECT uuid_node(uuid_generate_v1mc()) <> uuid_node(uuid_generate_v1mc());