[PATCH v2 2/2] tests/tcg/multiarch: Add tests for implemented alsa sound timer ioctls

2020-02-13 Thread Filip Bozuta
This patch adds tests for following 14 implemented alsa timer ioctls:

* SNDRV_TIMER_IOCTL_PVERSION* SNDRV_TIMER_IOCTL_INFO
* SNDRV_TIMER_IOCTL_NEXT_DEVICE * SNDRV_TIMER_IOCTL_PARAMS
* SNDRV_TIMER_IOCTL_TREAD   * SNDRV_TIMER_IOCTL_STATUS
* SNDRV_TIMER_IOCTL_GINFO   * SNDRV_TIMER_IOCTL_START
* SNDRV_TIMER_IOCTL_GPARAMS * SNDRV_TIMER_IOCTL_STOP
* SNDRV_TIMER_IOCTL_GSTATUS * SNDRV_TIMER_IOCTL_CONTINUE
* SNDRV_TIMER_IOCTL_SELECT  * SNDRV_TIMER_IOCTL_PAUSE

Names and descriptions of these ioctls can be found in patches that
implement them.

Test folder for these ioctl tests is located at
"tests/tcg/multiarch/alsa-timer-ioctl-tests/"

There are two folders located in the test folder, one for test that  was written
manually ("/manual-test") and one for the test that  was obtained remotely 
("/remote-test").

Manual test:

This test was written manually to test all the implemented alsa timer ioctls
and was added at "/manual-test/alsa-timer-ioctl-manual-test.c". A separate 
test
function was written for each ioctl. Each of these functions uses a global 
test
macro 'TEST_ALSA_IOCTL' to run these tests. The file can be run to test all 
ioctls
or it can test only the specified ioctls. This depends on the commands 
specified
when running the test.

For Example (assuming 'rtc-ioctl-manual-test' is the compiled .exe file):

  running './alsa-timer-ioctl-manual-test SNDRV_TIMER_IOCTL_TREAD' tests 
only the
  ioctl SNDRV_TIMER_IOCTL_TREAD

  running './alsa-timer-ioctl-manual-test  SNDRV_TIMER_IOCTL_INFO 
SNDRV_TIMER_IOCTL_STOP
  SNDRV_TIMER_IOCTL_PAUSE' tests ioctls SNDRV_TIMER_IOCTL_INFO, 
SNDRV_TIMER_IOCTL_STOP,
  SNDRV_TIMER_IOCTL_PAUSE

If no ioctl is specified when running the test file, all the ioctls
are tested:

  running './rtc-ioctl-test' tests all ioctls

Remote test:

Besides the manual tests, a remote alsa timer ioctl test was added at
"/remote-test/timer.c". This test file was downloaded from a git repository
that contains alsa ioctl test suite. This repository is located at
"https://github.com/takaswie/alsa-ioctl-test";. It is used to test all of the
alsa timer ioctls at once by running a test macro defined in that file.
The file was modified a little bit by adding an output line that shows which
test passed and at which test the program aborts. It was also modified so 
that
it doesn't have styling problems detected by 'scripts/checkpatch.pl'.

Signed-off-by: Filip Bozuta 
---
 .../manual-test/alsa-timer-ioctl-manual-test.c | 294 +
 .../alsa-timer-ioctl-tests/remote-test/timer.c | 158 +++
 2 files changed, 452 insertions(+)
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/manual-test/alsa-timer-ioctl-manual-test.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/remote-test/timer.c

diff --git 
a/tests/tcg/multiarch/alsa-timer-ioctl-tests/manual-test/alsa-timer-ioctl-manual-test.c
 
b/tests/tcg/multiarch/alsa-timer-ioctl-tests/manual-test/alsa-timer-ioctl-manual-test.c
new file mode 100644
index 000..95803ff
--- /dev/null
+++ 
b/tests/tcg/multiarch/alsa-timer-ioctl-tests/manual-test/alsa-timer-ioctl-manual-test.c
@@ -0,0 +1,294 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ERROR -1
+
+#define TEST_ALSA_IOCTL(fd, command, argument, supported) \
+do {  \
+printf("%s:\n", #command);\
+if (ioctl(fd, command, argument) == ERROR) {  \
+perror("ioctl");  \
+printf("\n"); \
+supported = false;\
+} \
+} while (0)
+
+static bool test_pversion(int fd, bool supported)
+{
+int version = 0;
+
+TEST_ALSA_IOCTL(fd, SNDRV_TIMER_IOCTL_PVERSION, &version, supported);
+if (supported) {
+printf("Timer version: %d\n", version);
+printf("\n");
+}
+return supported;
+}
+
+static bool test_next_device(int fd, bool supported)
+{
+struct snd_timer_id id = {1, 0, 0, 0, 0};
+
+TEST_ALSA_IOCTL(fd, SNDRV_TIMER_IOCTL_NEXT_DEVICE, &id, supported);
+if (supported) {
+printf("Timer dev_class: %d\n", id.dev_class);
+printf("Timer dev_sclass: %d\n", id.dev_class);
+printf("Timer card: %d\n", id.dev_class);
+printf("Timer device: %d\n", id.dev_class);
+printf("Timer subdevice: %d\n", id.dev_class);
+printf("\n");
+}
+return supported;
+}
+
+static bool test_tread(int fd, bool supported)
+{
+int tread = 1;
+
+TEST_ALSA_IOCTL(fd, SNDRV_TIMER_IOCTL_TREAD, &tread, supported);
+if (supported) {
+printf("Enhanced read enabled!\n");
+printf("\n");
+  

Re: [PATCH v2 2/2] tests/tcg/multiarch: Add tests for implemented alsa sound timer ioctls

2020-02-13 Thread Aleksandar Markovic
3:26 PM Čet, 13.02.2020. Filip Bozuta  је
написао/ла:
>
> +int main(int argc, char **argv)
> +{
> +char ioctls[15][35] = {"SNDRV_TIMER_IOCTL_PVERSION",
> +   "SNDRV_TIMER_IOCTL_INFO",
> +   "SNDRV_TIMER_IOCTL_NEXT_DEVICE",
> +   "SNDRV_TIMER_IOCTL_PARAMS",
> +   "SNDRV_TIMER_IOCTL_TREAD",
> +   "SNDRV_TIMER_IOCTL_STATUS",
> +   "SNDRV_TIMER_IOCTL_GINFO",
> +   "SNDRV_TIMER_IOCTL_START",
> +   "SNDRV_TIMER_IOCTL_GPARAMS",
> +   "SNDRV_TIMER_IOCTL_STOP",
> +   "SNDRV_TIMER_IOCTL_GSTATUS",
> +   "SNDRV_TIMER_IOCTL_CONTINUE",
> +   "SNDRV_TIMER_IOCTL_SELECT",
> +   "SNDRV_TIMER_IOCTL_PAUSE"};
> +
> +bool (*const funcs[]) (int, bool) = {
> +  test_pversion,
> +  test_next_device,
> +  test_tread,
> +  test_ginfo,
> +  test_gparams,
> +  test_gstatus,
> +  test_select,
> +  test_info,
> +  test_params,
> +  test_status,
> +  test_start,
> +  test_pause,
> +  test_continue,
> +  test_stop,
> +  NULL
> +};
> +

Order of these two arrays don't match, and that leads to the wrong choice
of test function later on in the code. For example, if one chooses
"SNDRV_TIMER_IOCTL_STATUS" in the command line, one will end up testing
"SNDRV_TIMER_IOCTL_GSTATUS", if one chooses "SNDRV_TIMER_IOCTL_INFO", one
will end up testing "SNDRV_TIMER_IOCTL_NEXT_DEVICE", etc. Nice feature
(ability to test just a single ioctl), but it needs to be fixed.

Thanks,
Aleksandar