Commit 9a9ad69c authored by Ramon Nou's avatar Ramon Nou Committed by Ramon Nou
Browse files

dup dup2 testing

syscall testing coverage
parent 4110d879
......@@ -233,6 +233,7 @@ gkfs:unit:
- ctest -j $(nproc) -L unit::all --output-junit report.xml
## capture coverage information
- cd ${BUILD_PATH}
- ${CI_SCRIPTS_DIR}/coverage.sh
--verbose
--capture unit
......
......@@ -74,11 +74,18 @@ def test_open_error(gkfs_daemon, gkfs_client):
# Undefined in man
ret = gkfs_client.open(file2, os.O_CREAT | os.O_WRONLY)
assert ret.retval == 10000
# RDWR
ret = gkfs_client.open(file2, os.O_RDWR)
assert ret.retval == 10000
# RD
ret = gkfs_client.open(file2, os.O_RDONLY)
assert ret.retval == 10000
# Truncate the file
ret = gkfs_client.open(file2, os.O_TRUNC | os.O_WRONLY)
assert ret.retval == 10000
# Open unexistent file
ret = gkfs_client.open(file3, os.O_WRONLY)
......@@ -150,3 +157,14 @@ def test_check_parents(gkfs_daemon, gkfs_client):
assert ret.retval == -1
assert ret.errno == errno.ENOTDIR
def test_dup(gkfs_daemon, gkfs_client):
file = gkfs_daemon.mountdir / "file"
ret = gkfs_client.open(file, os.O_CREAT | os.O_WRONLY)
assert ret.retval == 10000
ret = gkfs_client.dup_validate(file)
assert ret.retval == 0
assert ret.errno == 0
################################################################################
# Copyright 2018-2022, Barcelona Supercomputing Center (BSC), Spain #
# Copyright 2015-2022, Johannes Gutenberg Universitaet Mainz, Germany #
# #
# This software was partially supported by the #
# EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu). #
# #
# This software was partially supported by the #
# ADA-FS project under the SPPEXA project funded by the DFG. #
# #
# This file is part of GekkoFS. #
# #
# GekkoFS is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# GekkoFS is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with GekkoFS. If not, see <https://www.gnu.org/licenses/>. #
# #
# SPDX-License-Identifier: GPL-3.0-or-later #
################################################################################
from sre_parse import State
import harness
from pathlib import Path
import errno
import stat
import os
import ctypes
import sys
import pytest
from harness.logger import logger
import ctypes
nonexisting = "nonexisting"
def test_syscalls(gkfs_daemon, gkfs_client):
file = gkfs_daemon.mountdir / "file"
ret = gkfs_client.open(file, os.O_CREAT | os.O_WRONLY)
assert ret.retval == 10000
ret = gkfs_client.syscall_coverage(file)
assert ret.retval == 0
assert ret.errno == 0
......@@ -65,6 +65,8 @@ add_executable(gkfs.io
gkfs.io/unlink.cpp
gkfs.io/access.cpp
gkfs.io/statfs.cpp
gkfs.io/dup_validate.cpp
gkfs.io/syscall_coverage.cpp
)
include(FetchContent)
......
......@@ -117,4 +117,10 @@ symlink_init(CLI::App& app);
void
unlink_init(CLI::App& app);
void
dup_validate_init(CLI::App& app);
void
syscall_coverage_init(CLI::App& app);
#endif // IO_COMMANDS_HPP
/*
Copyright 2018-2022, Barcelona Supercomputing Center (BSC), Spain
Copyright 2015-2022, Johannes Gutenberg Universitaet Mainz, Germany
This software was partially supported by the
EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu).
This software was partially supported by the
ADA-FS project under the SPPEXA project funded by the DFG.
This file is part of GekkoFS.
GekkoFS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
GekkoFS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GekkoFS. If not, see <https://www.gnu.org/licenses/>.
SPDX-License-Identifier: GPL-3.0-or-later
*/
/* C++ includes */
#include <CLI11/CLI11.hpp>
#include <nlohmann/json.hpp>
#include <memory>
#include <fmt/format.h>
#include <commands.hpp>
#include <reflection.hpp>
#include <serialize.hpp>
#include <binary_buffer.hpp>
/* C includes */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
using json = nlohmann::json;
struct dup_validate_options {
bool verbose{};
std::string pathname;
REFL_DECL_STRUCT(dup_validate_options, REFL_DECL_MEMBER(bool, verbose),
REFL_DECL_MEMBER(std::string, pathname));
};
struct dup_validate_output {
int retval;
int errnum;
REFL_DECL_STRUCT(dup_validate_output, REFL_DECL_MEMBER(int, retval),
REFL_DECL_MEMBER(int, errnum));
};
void
to_json(json& record, const dup_validate_output& out) {
record = serialize(out);
}
void
dup_validate_exec(const dup_validate_options& opts) {
int fd = ::open(opts.pathname.c_str(), O_WRONLY);
if(fd == -1) {
if(opts.verbose) {
fmt::print(
"dup_validate(pathname=\"{}\") = {}, errno: {} [{}]\n",
opts.pathname, fd, errno, ::strerror(errno));
return;
}
json out = dup_validate_output{fd, errno};
fmt::print("{}\n", out.dump(2));
return;
}
auto rv = ::dup(fd);
auto rv2 = ::dup2(fd, rv);
if(opts.verbose) {
fmt::print(
"dup_validate(pathname=\"{}\") = {}, errno: {} [{}]\n",
opts.pathname, rv, errno, ::strerror(errno));
return;
}
if(rv < 0 || rv2 < 0) {
json out = dup_validate_output{(int) rv, errno};
fmt::print("{}\n", out.dump(2));
return;
}
rv = 0;
errno = 0;
json out = dup_validate_output{(int) rv, errno};
fmt::print("{}\n", out.dump(2));
return;
}
void
dup_validate_init(CLI::App& app) {
// Create the option and subcommand objects
auto opts = std::make_shared<dup_validate_options>();
auto* cmd = app.add_subcommand(
"dup_validate",
"Execute dup, dup2, and dup3 returns 0 if the file descriptor is valid");
// Add options to cmd, binding them to opts
cmd->add_flag("-v,--verbose", opts->verbose,
"Produce human writeable output");
cmd->add_option("pathname", opts->pathname, "File name")
->required()
->type_name("");
cmd->callback([opts]() { dup_validate_exec(*opts); });
}
......@@ -65,6 +65,8 @@ init_commands(CLI::App& app) {
getcwd_validate_init(app);
symlink_init(app);
unlink_init(app);
dup_validate_init(app);
syscall_coverage_init(app);
}
......
/*
Copyright 2018-2022, Barcelona Supercomputing Center (BSC), Spain
Copyright 2015-2022, Johannes Gutenberg Universitaet Mainz, Germany
This software was partially supported by the
EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu).
This software was partially supported by the
ADA-FS project under the SPPEXA project funded by the DFG.
This file is part of GekkoFS.
GekkoFS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
GekkoFS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GekkoFS. If not, see <https://www.gnu.org/licenses/>.
SPDX-License-Identifier: GPL-3.0-or-later
*/
/* C++ includes */
#include <CLI11/CLI11.hpp>
#include <nlohmann/json.hpp>
#include <memory>
#include <fmt/format.h>
#include <commands.hpp>
#include <reflection.hpp>
#include <serialize.hpp>
#include <binary_buffer.hpp>
/* C includes */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
using json = nlohmann::json;
struct syscall_coverage_options {
bool verbose{};
std::string pathname;
REFL_DECL_STRUCT(syscall_coverage_options, REFL_DECL_MEMBER(bool, verbose),
REFL_DECL_MEMBER(std::string, pathname));
};
struct syscall_coverage_output {
int retval;
int errnum;
REFL_DECL_STRUCT(syscall_coverage_output, REFL_DECL_MEMBER(int, retval),
REFL_DECL_MEMBER(int, errnum));
};
void
to_json(json& record, const syscall_coverage_output& out) {
record = serialize(out);
}
void output (const std::string syscall, const int ret, const syscall_coverage_options& opts) {
if(opts.verbose) {
fmt::print(
"syscall_coverage[{}](pathname=\"{}\") = {}, errno: {} [{}]\n",
syscall, opts.pathname, ret, errno, ::strerror(errno));
}
json out = syscall_coverage_output{ret, errno};
fmt::print("{}\n", out.dump(2));
}
void
syscall_coverage_exec(const syscall_coverage_options& opts) {
int fd = ::open(opts.pathname.c_str(), O_RDWR);
if(fd == -1) {
output ("open", fd, opts);
return;
}
// Internal
auto rv = ::faccessat(AT_FDCWD, opts.pathname.c_str(), F_OK, 0);
if(rv < 0) {
output ("faccessat", rv, opts);
return;
}
// External
rv = ::faccessat(AT_FDCWD, "/tmp", F_OK, 0);
if(rv < 0) {
output ("faccessat, external", rv, opts);
return;
}
// lstat
struct stat st;
rv = ::lstat(opts.pathname.c_str(), &st);
if (rv < 0) {
output ("lstat", rv, opts);
return;
}
rv = ::fchmod(fd, 0777);
if (errno != ENOTSUP) {
output ("fchmod", rv, opts);
return;
}
rv = ::fchmodat(AT_FDCWD, opts.pathname.c_str(), 0777, 0);
if (errno != ENOTSUP) {
output ("fchmodat", rv, opts);
return;
}
rv = ::dup3(fd, 0, 0);
if (errno != ENOTSUP) {
output ("dup3", rv, opts);
return;
}
// fcntl
rv = ::fcntl(fd, F_GETFD);
if (rv < 0) {
output ("fcntl, F_GETFD", rv, opts);
return;
}
rv = ::fcntl(fd, F_GETFL);
if (rv < 0 || rv != O_RDWR) {
output ("fcntl, F_GETFL", rv, opts);
return;
}
rv = ::fcntl(fd, F_SETFD, 0);
if (rv < 0) {
output ("fcntl, F_SETFD", rv, opts);
return;
}
rv = ::fcntl(fd, F_SETFL, 0);
if (errno != ENOTSUP) {
output ("fcntl, F_SETFL", rv, opts);
return;
}
rv = 0;
errno = 0;
json out = syscall_coverage_output{(int) rv, errno};
fmt::print("{}\n", out.dump(2));
return;
}
void
syscall_coverage_init(CLI::App& app) {
// Create the option and subcommand objects
auto opts = std::make_shared<syscall_coverage_options>();
auto* cmd = app.add_subcommand(
"syscall_coverage",
"Execute severals syscalls");
// Add options to cmd, binding them to opts
cmd->add_flag("-v,--verbose", opts->verbose,
"Produce human writeable output");
cmd->add_option("pathname", opts->pathname, "File name")
->required()
->type_name("");
cmd->callback([opts]() { syscall_coverage_exec(*opts); });
}
......@@ -254,7 +254,8 @@ class Daemon:
'--dbbackend', self._database,
'--output-stats', self.logdir / 'stats.log',
'--enable-collection',
'--enable-chunkstats' ]
'--enable-chunkstats',
'--enable-prometheus' ]
if self._database == "parallaxdb" :
args.append('--clean-rootdir-finish')
......
......@@ -414,7 +414,25 @@ class GetcwdvalidateOutputSchema(Schema):
def make_object(self, data, **kwargs):
return namedtuple('GetcwdvalidateReturn', ['retval', 'path', 'errno'])(**data)
class DupValidateOutputSchema(Schema):
"""Schema to deserialize the results of an dup, dup2, dup3 execution"""
retval = fields.Integer(required=True)
errno = Errno(data_key='errnum', required=True)
@post_load
def make_object(self, data, **kwargs):
return namedtuple('DupValidateReturn', ['retval', 'errno'])(**data)
class SyscallCoverageOutputSchema(Schema):
"""Schema to deserialize the results of a syscall coverage execution"""
retval = fields.Integer(required=True)
errno = Errno(data_key='errnum', required=True)
@post_load
def make_object(self, data, **kwargs):
return namedtuple('SyscallCoverageReturn', ['retval', 'errno'])(**data)
class SymlinkOutputSchema(Schema):
"""Schema to deserialize the results of an symlink execution"""
......@@ -479,6 +497,8 @@ class IOParser:
'chdir' : ChdirOutputSchema(),
'getcwd_validate' : GetcwdvalidateOutputSchema(),
'symlink' : SymlinkOutputSchema(),
'dup_validate' : DupValidateOutputSchema(),
'syscall_coverage' : SyscallCoverageOutputSchema(),
}
def parse(self, command, output):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment