summaryrefslogtreecommitdiff
path: root/test/regression/usbx_uxe_host_printer_test.c
blob: 77d96195657c66c7d0ce1854f711f3bad7837135 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/***************************************************************************/
/* Copyright (c) 2024 Microsoft Corporation                                */
/* Copyright (c) 2026 Eclipse ThreadX contributors                         */
/*                                                                         */
/* This program and the accompanying materials are made available under    */
/* the terms of the MIT License which is available at                      */
/* https://opensource.org/licenses/MIT.                                    */
/*                                                                         */
/* SPDX-License-Identifier: MIT                                            */
/***************************************************************************/

/* This test is designed to test the ux_utility_descriptor_pack.  */

#include <stdio.h>
#include "tx_api.h"
#include "ux_api.h"
#include "ux_system.h"
#include "ux_utility.h"

#include "ux_host_stack.h"
#include "ux_device_stack.h"

#include "ux_host_class_printer.h"

#include "ux_test.h"

/* Define USBX test constants.  */

#define UX_TEST_STACK_SIZE      4096
#define UX_TEST_BUFFER_SIZE     2048
#define UX_TEST_MEMORY_SIZE     (64*1024)


/* Define the counters used in the test application...  */

static ULONG                           error_counter = 0;

/* Define USBX test global variables.  */


/* Define prototypes for external Host Controller's (HCDs), classes and clients.  */

static TX_THREAD           ux_test_thread_simulation_0;
static void                ux_test_thread_simulation_0_entry(ULONG);


/* Prototype for test control return.  */

void  test_control_return(UINT status);


/* Define what the initial system looks like.  */

#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void usbx_uxe_host_printer_test_application_define(void *first_unused_memory)
#endif
{

UINT status;
CHAR                            *stack_pointer;
CHAR                            *memory_pointer;

    /* Inform user.  */
    printf("Running uxe_host_printer APIs Test.................................... ");
#if !defined(UX_HOST_CLASS_PRINTER_ENABLE_ERROR_CHECKING)
#warning Tests skipped due to compile option!
    printf("SKIP SUCCESS!\n");
    test_control_return(0);
    return;
#endif

    /* Initialize the free memory pointer.  */
    stack_pointer = (CHAR *) first_unused_memory;
    memory_pointer = stack_pointer + (UX_TEST_STACK_SIZE * 2);

    /* Initialize USBX Memory.  */
    status =  ux_system_initialize(memory_pointer, UX_TEST_MEMORY_SIZE, UX_NULL, 0);

    /* Check for error.  */
    if (status != UX_SUCCESS)
    {

        printf("ERROR #%d\n", __LINE__);
        test_control_return(1);
    }

    /* Create the simulation thread.  */
    status =  tx_thread_create(&ux_test_thread_simulation_0, "test simulation", ux_test_thread_simulation_0_entry, 0,
            stack_pointer, UX_TEST_STACK_SIZE,
            20, 20, 1, TX_AUTO_START);

    /* Check for error.  */
    if (status != TX_SUCCESS)
    {

        printf("ERROR #%d\n", __LINE__);
        test_control_return(1);
    }
}


static void  ux_test_thread_simulation_0_entry(ULONG arg)
{
UINT                                            status;
UX_HOST_CLASS_PRINTER                           dummy_printer_inst;
UX_HOST_CLASS_PRINTER                           *dummy_printer = &dummy_printer_inst;
UCHAR                                           dummy_buffer[64];
ULONG                                           actual_length;
ULONG                                           printer_status;

    /* ux_host_class_printer_name_get()  */
    status = ux_host_class_printer_name_get(UX_NULL);
    UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);

    /* ux_host_class_printer_device_id_get() */
    status = ux_host_class_printer_device_id_get(UX_NULL, dummy_buffer, 64);
    UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);

    status = ux_host_class_printer_device_id_get(dummy_printer, UX_NULL, 64);
    UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);

    status = ux_host_class_printer_device_id_get(dummy_printer, dummy_buffer, 0);
    UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);

    /* ux_host_class_printer_read() */
    status = ux_host_class_printer_read(UX_NULL, dummy_buffer, 64, &actual_length);
    UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);

    status = ux_host_class_printer_read(dummy_printer, UX_NULL, 64, &actual_length);
    UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);

    status = ux_host_class_printer_read(dummy_printer, dummy_buffer, 64, UX_NULL);
    UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);

    /* ux_host_class_printer_soft_reset() */
    status = ux_host_class_printer_soft_reset(UX_NULL);
    UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);

    /* ux_host_class_printer_status_get() */
    status = ux_host_class_printer_status_get(UX_NULL, &printer_status);
    UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);

    status = ux_host_class_printer_status_get(dummy_printer, UX_NULL);
    UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);

    /* ux_host_class_printer_write() */
    status = ux_host_class_printer_write(UX_NULL, dummy_buffer, 64, &actual_length);
    UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);

    status = ux_host_class_printer_write(dummy_printer, UX_NULL, 64, &actual_length);
    UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);

    status = ux_host_class_printer_write(dummy_printer, dummy_buffer, 64, UX_NULL);
    UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);

    /* Sleep for a tick to make sure everything is complete.  */
    tx_thread_sleep(1);

    /* Check for errors from other threads.  */
    if (error_counter)
    {

        /* Test error.  */
        printf("ERROR #%d: total %ld errors\n", __LINE__, error_counter);
        test_control_return(1);
    }
    else
    {

        /* Successful test.  */
        printf("SUCCESS!\n");
        test_control_return(0);
    }
}