| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 665673c commit 0a7411c
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,27 @@ | |||
| 1 | + import machine | ||
| 2 | + | ||
| 3 | + # --------------------------------------------------------------------------- | ||
| 4 | + # machine.unique_id() contract test. | ||
| 5 | + # Verifies that unique_id is bytes, has expected 64-bit length (8 bytes), | ||
| 6 | + # is non-zero, and remains stable across repeated calls on the same boot. | ||
| 7 | + # --------------------------------------------------------------------------- | ||
| 8 | + | ||
| 9 | + print("***** Test 1: machine.unique_id() contract *****") | ||
| 10 | + uid0 = machine.unique_id() | ||
| 11 | + | ||
| 12 | + ok = True | ||
| 13 | + if not isinstance(uid0, bytes): | ||
| 14 | + ok = False | ||
| 15 | + | ||
| 16 | + if len(uid0) != 8: | ||
| 17 | + ok = False | ||
| 18 | + | ||
| 19 | + if not any(b != 0 for b in uid0): | ||
| 20 | + ok = False | ||
| 21 | + | ||
| 22 | + for _ in range(5): | ||
| 23 | + if machine.unique_id() != uid0: | ||
| 24 | + ok = False | ||
| 25 | + break | ||
| 26 | + | ||
| 27 | + print("PASS" if ok else "FAIL") | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + ***** Test 1: machine.unique_id() contract ***** | ||
| 2 | + PASS | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments