1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. 4f08c3bdfSopenharmony_ci * Copyright (c) 2017 Fujitsu Ltd. 5f08c3bdfSopenharmony_ci */ 6f08c3bdfSopenharmony_ci 7f08c3bdfSopenharmony_ci#include <errno.h> 8f08c3bdfSopenharmony_ci#include "tst_test.h" 9f08c3bdfSopenharmony_ci 10f08c3bdfSopenharmony_ci#define SIZE 512 11f08c3bdfSopenharmony_ci 12f08c3bdfSopenharmony_cistatic int fd; 13f08c3bdfSopenharmony_cistatic char buf[SIZE]; 14f08c3bdfSopenharmony_ci 15f08c3bdfSopenharmony_cistatic void verify_read(void) 16f08c3bdfSopenharmony_ci{ 17f08c3bdfSopenharmony_ci SAFE_LSEEK(fd, 0, SEEK_SET); 18f08c3bdfSopenharmony_ci 19f08c3bdfSopenharmony_ci TEST(read(fd, buf, SIZE)); 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_ci if (TST_RET == -1) 22f08c3bdfSopenharmony_ci tst_res(TFAIL | TTERRNO, "read(2) failed"); 23f08c3bdfSopenharmony_ci else 24f08c3bdfSopenharmony_ci tst_res(TPASS, "read(2) returned %ld", TST_RET); 25f08c3bdfSopenharmony_ci} 26f08c3bdfSopenharmony_ci 27f08c3bdfSopenharmony_cistatic void setup(void) 28f08c3bdfSopenharmony_ci{ 29f08c3bdfSopenharmony_ci memset(buf, '*', SIZE); 30f08c3bdfSopenharmony_ci fd = SAFE_OPEN("testfile", O_RDWR | O_CREAT, 0700); 31f08c3bdfSopenharmony_ci SAFE_WRITE(SAFE_WRITE_ALL, fd, buf, SIZE); 32f08c3bdfSopenharmony_ci} 33f08c3bdfSopenharmony_ci 34f08c3bdfSopenharmony_cistatic void cleanup(void) 35f08c3bdfSopenharmony_ci{ 36f08c3bdfSopenharmony_ci if (fd > 0) 37f08c3bdfSopenharmony_ci SAFE_CLOSE(fd); 38f08c3bdfSopenharmony_ci} 39f08c3bdfSopenharmony_ci 40f08c3bdfSopenharmony_cistatic struct tst_test test = { 41f08c3bdfSopenharmony_ci .test_all = verify_read, 42f08c3bdfSopenharmony_ci .setup = setup, 43f08c3bdfSopenharmony_ci .cleanup = cleanup, 44f08c3bdfSopenharmony_ci .needs_tmpdir = 1, 45f08c3bdfSopenharmony_ci}; 46