Implement RFC 4122-compliant UUIDs.
[sliver-openvswitch.git] / tests / uuid.at
1 AT_BANNER([UUID unit tests])
2
3 m4_define([UUID_REGEX], 
4   [[[0-9a-f]\{8\}-[0-9a-f]\{4\}-4[0-9a-f]\{3\}-[89ab][0-9a-f]\{3\}-[0-9a-f]\{12\}$]])
5
6 m4_define([CHECK_UUID],
7   [if expr "$uuid" : 'UUID_REGEX' > /dev/null
8    then
9       :
10    else
11      echo "$uuid: not a random UUID"
12      exit 1
13    fi])
14
15 # This test is a strict subset of the larger test down below, but it
16 # allows us to get test coverage data via OVS_CHECK_LCOV.
17 AT_SETUP([UUID generation])
18 AT_KEYWORDS([UUID])
19 OVS_CHECK_LCOV([test-uuid > uuid])
20 AT_CHECK([
21   uuid=`cat uuid`
22   CHECK_UUID])
23 AT_CLEANUP
24
25 # This test is a strict subset of the larger test down below, but it
26 # allows us to get test coverage data via OVS_CHECK_LCOV.
27 AT_SETUP([UUID parsing and serialization])
28 AT_KEYWORDS([UUID])
29 OVS_CHECK_LCOV([test-uuid f47ac10b-58cc-4372-a567-0e02b2c3d479], [0],
30                [f47ac10b-58cc-4372-a567-0e02b2c3d479
31 ])
32 AT_CLEANUP
33
34 AT_SETUP([UUID generation, parsing, serialization])
35 AT_KEYWORDS([UUID])
36 AT_CHECK([
37   uuids=
38   for i in m4_for([count], [1], [100], [1], [count ]); do
39      # Generate random UUID and check that it is in the expected format.
40      uuid=`test-uuid`
41      CHECK_UUID
42
43      # Verify that $uuid does not duplicate any UUID generated so far.
44      case $uuids in
45        *$uuid*) 
46          echo "$uuid: generated duplicate UUID"
47          exit 1
48      esac
49      uuids="$uuids $uuid"
50
51      # Verify that test-uuid parses and re-serializes this UUID correctly.
52      serialized=`test-uuid $uuid`
53      if test "$uuid" != "$serialized"; then
54        echo "$uuid: test-uuid serialized this as $serialized"
55        exit 1
56      fi
57    done], [0])
58 AT_CLEANUP