aboutsummaryrefslogtreecommitdiff
path: root/tests/uuid.at
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2009-09-24 15:02:36 -0700
committerBen Pfaff <blp@nicira.com>2009-11-04 15:24:40 -0800
commitd918d9d1128a98e4b2a398a501f541554fed3be8 (patch)
tree73134e34b952f6321b5554b324b41acb52b041a0 /tests/uuid.at
parentf38b84ea2b6b61d309c604faedd41ab3b0fcf16b (diff)
Implement RFC 4122-compliant UUIDs.
This UUID library will be used by the upcoming configuration database.
Diffstat (limited to 'tests/uuid.at')
-rw-r--r--tests/uuid.at58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/uuid.at b/tests/uuid.at
new file mode 100644
index 00000000..04b652a8
--- /dev/null
+++ b/tests/uuid.at
@@ -0,0 +1,58 @@
+AT_BANNER([UUID unit tests])
+
+m4_define([UUID_REGEX],
+ [[[0-9a-f]\{8\}-[0-9a-f]\{4\}-4[0-9a-f]\{3\}-[89ab][0-9a-f]\{3\}-[0-9a-f]\{12\}$]])
+
+m4_define([CHECK_UUID],
+ [if expr "$uuid" : 'UUID_REGEX' > /dev/null
+ then
+ :
+ else
+ echo "$uuid: not a random UUID"
+ exit 1
+ fi])
+
+# This test is a strict subset of the larger test down below, but it
+# allows us to get test coverage data via OVS_CHECK_LCOV.
+AT_SETUP([UUID generation])
+AT_KEYWORDS([UUID])
+OVS_CHECK_LCOV([test-uuid > uuid])
+AT_CHECK([
+ uuid=`cat uuid`
+ CHECK_UUID])
+AT_CLEANUP
+
+# This test is a strict subset of the larger test down below, but it
+# allows us to get test coverage data via OVS_CHECK_LCOV.
+AT_SETUP([UUID parsing and serialization])
+AT_KEYWORDS([UUID])
+OVS_CHECK_LCOV([test-uuid f47ac10b-58cc-4372-a567-0e02b2c3d479], [0],
+ [f47ac10b-58cc-4372-a567-0e02b2c3d479
+])
+AT_CLEANUP
+
+AT_SETUP([UUID generation, parsing, serialization])
+AT_KEYWORDS([UUID])
+AT_CHECK([
+ uuids=
+ for i in m4_for([count], [1], [100], [1], [count ]); do
+ # Generate random UUID and check that it is in the expected format.
+ uuid=`test-uuid`
+ CHECK_UUID
+
+ # Verify that $uuid does not duplicate any UUID generated so far.
+ case $uuids in
+ *$uuid*)
+ echo "$uuid: generated duplicate UUID"
+ exit 1
+ esac
+ uuids="$uuids $uuid"
+
+ # Verify that test-uuid parses and re-serializes this UUID correctly.
+ serialized=`test-uuid $uuid`
+ if test "$uuid" != "$serialized"; then
+ echo "$uuid: test-uuid serialized this as $serialized"
+ exit 1
+ fi
+ done], [0])
+AT_CLEANUP