Skip to content

Commit eaad7a4

Browse files
committed
Create /sys/block symlink for block devices
Other part of #41
1 parent 2b16187 commit eaad7a4

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Fix compilation on sparc with gcc 4.9.
44
- Support attributes with leading directory names, such as "queue/rotational".
55
(issue #41)
6+
- Create /sys/block symlink for block devices (other part of issue #41).
67

78
0.8.5 (2014-07-11)
89
------------------

src/umockdev.vala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,15 @@ public class Testbed: GLib.Object {
412412
assert(FileUtils.symlink(Path.build_filename("..", "..", dev_path_no_sys),
413413
Path.build_filename(class_dir, Path.get_basename(name))) == 0);
414414

415+
/* /sys/block symlink */
416+
if (subsystem == "block") {
417+
var block_dir = Path.build_filename(this.sys_dir, "block");
418+
if (DirUtils.create_with_parents(block_dir, 0755) != 0)
419+
error("cannot create block dir '%s': %s", block_dir, strerror(errno));
420+
assert (FileUtils.symlink(Path.build_filename("..", dev_path_no_sys),
421+
Path.build_filename(block_dir, Path.get_basename(name))) == 0);
422+
}
423+
415424
/* bus symlink */
416425
if (subsystem == "usb" || subsystem == "pci") {
417426
class_dir = Path.build_filename(this.sys_dir, "bus", subsystem, "devices");

tests/test-umockdev.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,35 @@ t_testbed_child_device(UMockdevTestbedFixture * fixture, gconstpointer data)
339339
g_free(input);
340340
}
341341

342+
/* UMockdevTestbed add_device() with adding a block device */
343+
static void
344+
t_testbed_add_block_device(UMockdevTestbedFixture * fixture, gconstpointer data)
345+
{
346+
gchar *syspath;
347+
348+
syspath = umockdev_testbed_add_device(fixture->testbed, "block", "scribble", NULL,
349+
/* attributes */
350+
"size", "10000", NULL,
351+
/* properties */
352+
"ID_TYPE", "disk", NULL);
353+
g_assert(syspath);
354+
g_assert_cmpstr(syspath, ==, "/sys/devices/scribble");
355+
356+
/* check attributes */
357+
g_assert(g_file_test("/sys/devices/scribble/size", G_FILE_TEST_IS_REGULAR));
358+
g_assert(g_file_test("/sys/devices/scribble/uevent", G_FILE_TEST_IS_REGULAR));
359+
g_assert(g_file_test("/sys/devices/scribble/subsystem", G_FILE_TEST_IS_SYMLINK));
360+
361+
/* check class symlinks */
362+
g_assert(g_file_test("/sys/class/block/scribble", G_FILE_TEST_IS_SYMLINK));
363+
g_assert(g_file_test("/sys/class/block/scribble/size", G_FILE_TEST_IS_REGULAR));
364+
365+
g_assert(g_file_test("/sys/block/scribble", G_FILE_TEST_IS_SYMLINK));
366+
g_assert(g_file_test("/sys/block/scribble/size", G_FILE_TEST_IS_REGULAR));
367+
368+
g_free(syspath);
369+
}
370+
342371
struct TestbedErrorCatcherData {
343372
unsigned counter;
344373
GLogLevelFlags last_level;
@@ -1858,6 +1887,8 @@ main(int argc, char **argv)
18581887
t_testbed_add_devicev, t_testbed_fixture_teardown);
18591888
g_test_add("/umockdev-testbed/add_device", UMockdevTestbedFixture, NULL, t_testbed_fixture_setup,
18601889
t_testbed_add_device, t_testbed_fixture_teardown);
1890+
g_test_add("/umockdev-testbed/add_block_device", UMockdevTestbedFixture, NULL, t_testbed_fixture_setup,
1891+
t_testbed_add_block_device, t_testbed_fixture_teardown);
18611892
g_test_add("/umockdev-testbed/add_device_errors", UMockdevTestbedFixture, NULL, t_testbed_fixture_setup,
18621893
t_testbed_add_device_errors, t_testbed_fixture_teardown);
18631894
g_test_add("/umockdev-testbed/child_device", UMockdevTestbedFixture, NULL, t_testbed_fixture_setup,

0 commit comments

Comments
 (0)