Skip to content

Commit

Permalink
Add unit tests for cros_ec device
Browse files Browse the repository at this point in the history
  • Loading branch information
fandango96 committed Jun 9, 2024
1 parent 3cbc9e1 commit 5c5b0f6
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 1 deletion.
4 changes: 4 additions & 0 deletions devices/cros_ec/crosfingerprint.ioctl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@DEV /dev/cros_fp
CROS_EC_DEV_IOCXCMD_V2 4 000000000204000004000000040000000000000080000000
CROS_EC_DEV_IOCXCMD_V2 48 010000000304000000000000300000000000000046504320090000001B020000010000009466000047524559A000A0000800FF0324140000050001000100000004000000
CROS_EC_DEV_IOCXCMD_V2 22 000000000704000000000000160000000000000065630100B44A020007B30300DC33505A070000000000
93 changes: 93 additions & 0 deletions devices/cros_ec/crosfingerprint.umockdev
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
P: /devices/platform/AMDI0020:01/AMDI0020:01:0/AMDI0020:01:0.0/serial0/serial0-0/cros-ec-dev.2.auto/misc/cros_fp
N: cros_fp
E: DEVNAME=/dev/cros_fp
E: MAJOR=10
E: MINOR=122
E: SUBSYSTEM=misc
A: dev=10:122\n
L: device=../../../cros-ec-dev.2.auto
A: power/control=auto\n
A: power/runtime_active_time=0\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n

P: /devices/platform/AMDI0020:01/AMDI0020:01:0/AMDI0020:01:0.0/serial0/serial0-0/cros-ec-dev.2.auto
E: DRIVER=cros-ec-dev
E: ID_PATH=platform-AMDI0020:01-platform-cros-ec-dev.2.auto
E: ID_PATH_TAG=platform-AMDI0020_01-platform-cros-ec-dev_2_auto
E: ID_VENDOR_FROM_DATABASE=Amdek Corporation
E: MODALIAS=platform:cros-ec-dev
E: SUBSYSTEM=platform
L: driver=../../../../../../../../bus/platform/drivers/cros-ec-dev
A: driver_override=(null)\n
A: modalias=platform:cros-ec-dev\n
A: power/control=auto\n
A: power/runtime_active_time=0\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n

P: /devices/platform/AMDI0020:01/AMDI0020:01:0/AMDI0020:01:0.0/serial0/serial0-0
E: DRIVER=cros-ec-uart
E: MODALIAS=of:NcrfpTCgoogle,cros-ec-uart
E: SUBSYSTEM=serial
L: driver=../../../../../../../bus/serial/drivers/cros-ec-uart
L: firmware_node=../../../../../../LNXSYSTM:00/LNXSYBUS:00/AMDI0020:01/PRP0001:00
A: modalias=of:NcrfpTCgoogle,cros-ec-uart\n
A: power/control=auto\n
A: power/runtime_active_time=0\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n

P: /devices/platform/AMDI0020:01/AMDI0020:01:0/AMDI0020:01:0.0/serial0
E: SUBSYSTEM=serial
L: firmware_node=../../../../../LNXSYSTM:00/LNXSYBUS:00/AMDI0020:01
A: power/wakeup=disabled\n
A: power/wakeup_abort_count=\n
A: power/wakeup_active=\n
A: power/wakeup_active_count=\n
A: power/wakeup_count=\n
A: power/wakeup_expire_count=\n
A: power/wakeup_last_time_ms=\n
A: power/wakeup_max_time_ms=\n
A: power/wakeup_total_time_ms=\n
L: software_node=../../../../../../kernel/software_nodes/node1
A: waiting_for_supplier=0\n

P: /devices/platform/AMDI0020:01/AMDI0020:01:0/AMDI0020:01:0.0
E: DEVTYPE=port
E: DRIVER=port
E: SUBSYSTEM=serial-base
L: driver=../../../../../bus/serial-base/drivers/port
A: power/autosuspend_delay_ms=500\n
A: power/control=auto\n
A: power/runtime_active_time=31736669\n
A: power/runtime_status=active\n
A: power/runtime_suspended_time=5190\n

P: /devices/platform/AMDI0020:01/AMDI0020:01:0
E: DEVTYPE=ctrl
E: DRIVER=ctrl
E: SUBSYSTEM=serial-base
L: driver=../../../../bus/serial-base/drivers/ctrl
A: power/control=auto\n
A: power/runtime_active_time=31736676\n
A: power/runtime_status=active\n
A: power/runtime_suspended_time=5190\n

P: /devices/platform/AMDI0020:01
E: DRIVER=dw-apb-uart
E: ID_PATH=platform-AMDI0020:01
E: ID_PATH_TAG=platform-AMDI0020_01
E: ID_VENDOR_FROM_DATABASE=Amdek Corporation
E: MODALIAS=acpi:AMDI0020:
E: SUBSYSTEM=platform
L: driver=../../../bus/platform/drivers/dw-apb-uart
A: driver_override=(null)\n
L: firmware_node=../../LNXSYSTM:00/LNXSYBUS:00/AMDI0020:01
A: modalias=acpi:AMDI0020:\n
A: power/control=auto\n
A: power/runtime_active_time=31736687\n
A: power/runtime_status=active\n
A: power/runtime_suspended_time=5189\n
L: software_node=../../../kernel/software_nodes/node1

2 changes: 1 addition & 1 deletion docs/reference/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ gnome.gtkdoc('umockdev',
content_files: [version_xml],
gobject_typesfile: 'umockdev.types',
scan_args: ['--ignore-decorators', 'VALA_EXTERN'],
ignore_headers: ['uevent_sender.h', 'ioctl_tree.h', 'debug.h'],
ignore_headers: ['uevent_sender.h', 'ioctl.h', 'ioctl_tree.h', 'debug.h'],
dependencies: [glib, gobject, declare_dependency(link_with : [umockdev_lib])],
install: true,
)
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ if gudev.found()

test('umockdev-vala', executable('test-umockdev-vala',
'tests/test-umockdev-vala.vala',
include_directories: include_directories('src'),
dependencies: [glib, gobject, gio, gudev, vapi_posix, vapi_assertions, vapi_ioctl, vapi_glibc, vapi_selinux, selinux],
link_with: [umockdev_lib, umockdev_utils_lib],
vala_args: optional_defines),
Expand Down
9 changes: 9 additions & 0 deletions src/ioctl.vapi
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,14 @@ namespace Ioctl {

[CCode (cheader_filename = "ioctl.h")]
public const int CROS_EC_DEV_IOCXCMD_V2;
[CCode (cname = "struct cros_ec_command_v2", cheader_filename = "ioctl.h")]
public struct cros_ec_command_v2 {
uint32 version;
uint32 command;
uint32 outsize;
uint32 insize;
uint32 result;
uint8 data[0];
}
}

52 changes: 52 additions & 0 deletions tests/test-umockdev-vala.vala
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,56 @@ t_hidraw_ioctl ()
Posix.close (fd);
}

void
t_cros_ec_ioctl ()
{
var tb = new UMockdev.Testbed ();

string device;
checked_file_get_contents (Path.build_filename(rootdir + "/devices/cros_ec/crosfingerprint.umockdev"), out device);
tb_add_from_string (tb, device);

try {
tb.load_ioctl ("/dev/cros_fp", Path.build_filename(rootdir + "/devices/cros_ec/crosfingerprint.ioctl"));
} catch (Error e) {
error ("Cannot load ioctl file: %s", e.message);
}

int fd = Posix.open ("/dev/cros_fp", Posix.O_RDWR, 0);
assert_cmpint (fd, CompareOperator.GE, 0);

Ioctl.cros_ec_command_v2 *s_cmd = malloc (sizeof (Ioctl.cros_ec_command_v2) + 4);
assert_cmpint (Posix.ioctl (fd, Ioctl.CROS_EC_DEV_IOCXCMD_V2, s_cmd), CompareOperator.EQ, 4);
assert_cmpint (Posix.errno, CompareOperator.EQ, 0);
uint8 fpmode_data[] = {
0x80, 0x00, 0x00, 0x00
};
assert_cmpint (Posix.memcmp(s_cmd->data, fpmode_data, 4), CompareOperator.EQ, 0);

s_cmd = realloc(s_cmd, sizeof (Ioctl.cros_ec_command_v2) + 48);
assert_cmpint (Posix.ioctl (fd, Ioctl.CROS_EC_DEV_IOCXCMD_V2, s_cmd), CompareOperator.EQ, 48);
assert_cmpint (Posix.errno, CompareOperator.EQ, 0);
uint8 fpinfo_data[] = {
0x46, 0x50, 0x43, 0x20, 0x09, 0x00, 0x00, 0x00, 0x1B, 0x02, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x94, 0x66, 0x00, 0x00, 0x47, 0x52, 0x45, 0x59,
0xA0, 0x00, 0xA0, 0x00, 0x08, 0x00, 0xFF, 0x03, 0x24, 0x14, 0x00, 0x00,
0x05, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00
};
assert_cmpint (Posix.memcmp(s_cmd->data, fpinfo_data, 48), CompareOperator.EQ, 0);

s_cmd = realloc(s_cmd, sizeof (Ioctl.cros_ec_command_v2) + 22);
assert_cmpint (Posix.ioctl (fd, Ioctl.CROS_EC_DEV_IOCXCMD_V2, s_cmd), CompareOperator.EQ, 22);
assert_cmpint (Posix.errno, CompareOperator.EQ, 0);
uint8 fpstats_data[] = {
0x65, 0x63, 0x01, 0x00, 0xB4, 0x4A, 0x02, 0x00, 0x07, 0xB3, 0x03, 0x00,
0xDC, 0x33, 0x50, 0x5A, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00
};
assert_cmpint (Posix.memcmp(s_cmd->data, fpstats_data, 22), CompareOperator.EQ, 0);

free (s_cmd);
Posix.close (fd);
}

void
t_tty_stty ()
{
Expand Down Expand Up @@ -1153,6 +1203,8 @@ main (string[] args)

Test.add_func ("/umockdev-testbed-vala/hidraw_ioctl", t_hidraw_ioctl);

Test.add_func ("/umockdev-testbed-vala/cros_ec_ioctl", t_cros_ec_ioctl);

/* tests for mocking TTYs */
Test.add_func ("/umockdev-testbed-vala/tty_stty", t_tty_stty);
Test.add_func ("/umockdev-testbed-vala/tty_data", t_tty_data);
Expand Down

0 comments on commit 5c5b0f6

Please sign in to comment.