Skip to content

Commit

Permalink
test: read and dump sysfs tar file
Browse files Browse the repository at this point in the history
The library is able to scan the topology from a simple copy of
sysfs. There is no need to do any IOCTL, thus we can start test to
tree code.

This provides just the basic building blocks.

Signed-off-by: Daniel Wagner <[email protected]>
  • Loading branch information
igaw committed Jan 30, 2024
1 parent 550d6fe commit a7d9a78
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 0 deletions.
21 changes: 21 additions & 0 deletions scripts/collect-sysfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

Check failure on line 2 in scripts/collect-sysfs.sh

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: Missing or malformed SPDX-License-Identifier tag in line 2
filename=nvme-sysfs-$(hostname)-$(uname -r).tar.xz

declare -a dirs=(
"/sys/class/nvme"
"/sys/class/nvme-fabrics"
"/sys/class/nvme-generic"
"/sys/class/nvme-subsystem"
"/sys/bus/pci/slots"
)

files=""
for d in "${dirs[@]}"; do
files+="${d} "
for l in "${d}"/*; do
files+="$(readlink -f $l) "
done
done

tar -c -J -p -f "${filename}" ${files} 2> /dev/null
1 change: 1 addition & 0 deletions test/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,4 @@ endif

subdir('ioctl')
subdir('nbft')
subdir('sysfs')
Binary file not shown.
29 changes: 29 additions & 0 deletions test/sysfs/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# This file is part of libnvme.
# Copyright (c) 2024 SUSE LLC.
#
# Authors: Daniel Wagner <[email protected]>


sysfs = executable(
'test-sysfs',
['sysfs.c'],
dependencies: libnvme_dep,
include_directories: [incdir, internal_incdir]
)

sysfs_files= [
'nvme-sysfs-tw-carbon-6.8.0-rc1+.tar.xz'
]

tar = find_program('tar')
mkdir = find_program('mkdir')
setup = find_program('setup.sh')

foreach t_file : sysfs_files
r = run_command(setup, files('data'/t_file), meson.current_build_dir(), check: true)
d = r.stdout().strip()
e0 = 'LIBNVME_SYSFS_PATH=' + d
test('sysfs', sysfs, args : [ d ], env: [ e0 ])
endforeach
10 changes: 10 additions & 0 deletions test/sysfs/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

Check failure on line 2 in test/sysfs/setup.sh

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: Missing or malformed SPDX-License-Identifier tag in line 2
TARFILE=$1
BASEDIR=$2
TESTDIR="$BASEDIR/$(basename -s .tar.xz ${TARFILE})"

mkdir -p "${TESTDIR}"
tar -x -f "${TARFILE}" -C "${TESTDIR}"

echo "${TESTDIR}"
52 changes: 52 additions & 0 deletions test/sysfs/sysfs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/**
* This file is part of libnvme.
* Copyright (c) 2024 Daniel Wagner, SUSE LLC
*/

#include "nvme/tree.h"
#include <assert.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <arpa/inet.h>

#include <ccan/array_size/array_size.h>

#include <libnvme.h>
#include <nvme/private.h>

static bool test_sysfs(const char *path)
{
nvme_root_t r;
int err;

printf("path %s\n", path);

r = nvme_create_root(stdout, LOG_DEBUG);
assert(r);

err = nvme_scan_topology(r, NULL, NULL);
if (!err)
nvme_dump_tree(r);

nvme_free_tree(r);

return err == 0;
}

int main(int argc, char *argv[])
{
bool pass = true;

if (argc < 2) {
fprintf(stderr, "usage: test-sysfs DIR\n");
return EXIT_FAILURE;
}

pass &= test_sysfs(argv[1]);

fflush(stdout);

exit(pass ? EXIT_SUCCESS : EXIT_FAILURE);
}

0 comments on commit a7d9a78

Please sign in to comment.