Test driver for setxattr and getxattr. */
| 239 | |
| 240 | /* Test driver for setxattr and getxattr. */ |
| 241 | static int test_xattr(void) |
| 242 | { |
| 243 | int rc = 0; |
| 244 | int value_len; |
| 245 | struct io_uring ring; |
| 246 | char value[XATTR_SIZE]; |
| 247 | |
| 248 | /* Init io-uring queue. */ |
| 249 | int ret = io_uring_queue_init(QUEUE_DEPTH, &ring, 0); |
| 250 | if (ret) { |
| 251 | fprintf(stderr, "child: ring setup failed: %d\n", ret); |
| 252 | return -1; |
| 253 | } |
| 254 | |
| 255 | /* Create the test file. */ |
| 256 | t_create_file(FILENAME, 0); |
| 257 | |
| 258 | /* Test writing attributes. */ |
| 259 | if (io_uring_setxattr(&ring, FILENAME, KEY1, VALUE1, strlen(VALUE1), 0) < 0) { |
| 260 | fprintf(stderr, "Error setxattr cannot write key1\n"); |
| 261 | rc = -1; |
| 262 | goto Exit; |
| 263 | } |
| 264 | |
| 265 | if (io_uring_setxattr(&ring, FILENAME, KEY2, VALUE2, strlen(VALUE2), 0) < 0) { |
| 266 | fprintf(stderr, "Error setxattr cannot write key1\n"); |
| 267 | rc = -1; |
| 268 | goto Exit; |
| 269 | } |
| 270 | |
| 271 | /* Test reading attributes. */ |
| 272 | value_len = io_uring_getxattr(&ring, FILENAME, KEY1, value, XATTR_SIZE); |
| 273 | if (value_len != strlen(VALUE1) || strncmp(value, VALUE1, value_len)) { |
| 274 | fprintf(stderr, "Error: getxattr expected value: %s, returned value: %s\n", VALUE1, value); |
| 275 | rc = -1; |
| 276 | goto Exit; |
| 277 | } |
| 278 | |
| 279 | value_len = io_uring_getxattr(&ring, FILENAME, KEY2, value, XATTR_SIZE); |
| 280 | if (value_len != strlen(VALUE2) || strncmp(value, VALUE2, value_len)) { |
| 281 | fprintf(stderr, "Error: getxattr expected value: %s, returned value: %s\n", VALUE2, value); |
| 282 | rc = -1; |
| 283 | goto Exit; |
| 284 | } |
| 285 | |
| 286 | /* Cleanup. */ |
| 287 | Exit: |
| 288 | io_uring_queue_exit(&ring); |
| 289 | unlink(FILENAME); |
| 290 | |
| 291 | return rc; |
| 292 | } |
| 293 | |
| 294 | /* Test driver for failure cases of fsetxattr and fgetxattr. */ |
| 295 | static int test_failure_fxattr(void) |
no test coverage detected