1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org> 4f08c3bdfSopenharmony_ci * 5f08c3bdfSopenharmony_ci * Basic fsopen() failure tests. 6f08c3bdfSopenharmony_ci */ 7f08c3bdfSopenharmony_ci#include "tst_test.h" 8f08c3bdfSopenharmony_ci#include "lapi/fsmount.h" 9f08c3bdfSopenharmony_ci 10f08c3bdfSopenharmony_ciconst char *invalid_fs = "invalid"; 11f08c3bdfSopenharmony_ciconst char *valid_fs; 12f08c3bdfSopenharmony_ci 13f08c3bdfSopenharmony_cistatic struct tcase { 14f08c3bdfSopenharmony_ci char *name; 15f08c3bdfSopenharmony_ci const char **fs; 16f08c3bdfSopenharmony_ci unsigned int flags; 17f08c3bdfSopenharmony_ci int exp_errno; 18f08c3bdfSopenharmony_ci} tcases[] = { 19f08c3bdfSopenharmony_ci {"invalid-fs", &invalid_fs, 0, ENODEV}, 20f08c3bdfSopenharmony_ci {"invalid-flags", &valid_fs, 0x10, EINVAL}, 21f08c3bdfSopenharmony_ci}; 22f08c3bdfSopenharmony_ci 23f08c3bdfSopenharmony_cistatic void setup(void) 24f08c3bdfSopenharmony_ci{ 25f08c3bdfSopenharmony_ci fsopen_supported_by_kernel(); 26f08c3bdfSopenharmony_ci 27f08c3bdfSopenharmony_ci valid_fs = tst_device->fs_type; 28f08c3bdfSopenharmony_ci} 29f08c3bdfSopenharmony_ci 30f08c3bdfSopenharmony_cistatic void run(unsigned int n) 31f08c3bdfSopenharmony_ci{ 32f08c3bdfSopenharmony_ci struct tcase *tc = &tcases[n]; 33f08c3bdfSopenharmony_ci 34f08c3bdfSopenharmony_ci TEST(fsopen(*tc->fs, tc->flags)); 35f08c3bdfSopenharmony_ci 36f08c3bdfSopenharmony_ci if (TST_RET != -1) { 37f08c3bdfSopenharmony_ci SAFE_CLOSE(TST_RET); 38f08c3bdfSopenharmony_ci tst_res(TFAIL, "%s: fsopen() succeeded unexpectedly (index: %d)", 39f08c3bdfSopenharmony_ci tc->name, n); 40f08c3bdfSopenharmony_ci return; 41f08c3bdfSopenharmony_ci } 42f08c3bdfSopenharmony_ci 43f08c3bdfSopenharmony_ci if (tc->exp_errno != TST_ERR) { 44f08c3bdfSopenharmony_ci tst_res(TFAIL | TTERRNO, "%s: fsopen() should fail with %s", 45f08c3bdfSopenharmony_ci tc->name, tst_strerrno(tc->exp_errno)); 46f08c3bdfSopenharmony_ci return; 47f08c3bdfSopenharmony_ci } 48f08c3bdfSopenharmony_ci 49f08c3bdfSopenharmony_ci tst_res(TPASS | TTERRNO, "%s: fsopen() failed as expected", tc->name); 50f08c3bdfSopenharmony_ci} 51f08c3bdfSopenharmony_ci 52f08c3bdfSopenharmony_cistatic struct tst_test test = { 53f08c3bdfSopenharmony_ci .tcnt = ARRAY_SIZE(tcases), 54f08c3bdfSopenharmony_ci .test = run, 55f08c3bdfSopenharmony_ci .setup = setup, 56f08c3bdfSopenharmony_ci .needs_root = 1, 57f08c3bdfSopenharmony_ci .needs_device = 1, 58f08c3bdfSopenharmony_ci}; 59