Mike Frysinger | 3159ddc | 2022-09-07 08:24:21 -0400 | [diff] [blame] | 1 | /* Copyright 2020 Google LLC |
Chris Palmer | 29f7c7e | 2020-08-12 17:10:59 -0700 | [diff] [blame] | 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
| 6 | * |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following disclaimer |
| 11 | * in the documentation and/or other materials provided with the |
| 12 | * distribution. |
Mike Frysinger | 3159ddc | 2022-09-07 08:24:21 -0400 | [diff] [blame] | 13 | * * Neither the name of Google LLC nor the names of its |
Chris Palmer | 29f7c7e | 2020-08-12 17:10:59 -0700 | [diff] [blame] | 14 | * contributors may be used to endorse or promote products derived from |
| 15 | * this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #include "test_skel.h" |
| 31 | |
| 32 | #define BUFFER_SIZE 256 |
| 33 | |
| 34 | int main(int argc, char *argv[]) { |
| 35 | char buffer[BUFFER_SIZE]; |
| 36 | // Zero it out so we can check later that it's at least not all 0s. |
| 37 | memset(buffer, 0, BUFFER_SIZE); |
| 38 | bool buffer_contains_all_zeros = true; |
| 39 | |
| 40 | // Don't bother passing any flags. (If we're using lss, we might not have the |
| 41 | // right header files with the flags defined anyway, and we'd have to copy |
| 42 | // this in here too, and risk getting out of sync in yet another way.) |
| 43 | const ssize_t r = sys_getrandom(buffer, BUFFER_SIZE, 0); |
| 44 | |
| 45 | // Make sure it either worked, or that it's just not supported. |
| 46 | assert(r == BUFFER_SIZE || errno == ENOSYS); |
| 47 | |
| 48 | if (r == BUFFER_SIZE) { |
| 49 | // If all the bytes are 0, it didn't really work. |
| 50 | for (size_t i = 0; i < BUFFER_SIZE; ++i) { |
| 51 | if (buffer[i] != 0) { |
| 52 | buffer_contains_all_zeros = false; |
| 53 | } |
| 54 | } |
| 55 | assert(!buffer_contains_all_zeros); |
| 56 | } |
| 57 | |
| 58 | return 0; |
| 59 | } |