File: mnemonic_parser_t.c

package info (click to toggle)
fcml 1.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,536 kB
  • sloc: ansic: 57,510; cpp: 21,835; sh: 4,410; lex: 834; makefile: 508; yacc: 317
file content (221 lines) | stat: -rw-r--r-- 8,417 bytes parent folder | download | duplicates (2)
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
 * FCML - Free Code Manipulation Library.
 * Copyright (C) 2010-2020 Slawomir Wojtasiak
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "mnemonic_parser_t.h"

#include <fcml_mnemonic_parser.h>

#include <fcml_common.h>

fcml_bool fcml_tf_mnemonic_parser_suite_init(void) {
	return FCML_TRUE;
}

fcml_bool fcml_tf_mnemonic_parser_suite_cleanup(void) {
	return FCML_TRUE;
}

void fcml_tf_mnemonic_parser_test_parse_mnemonics(void) {

    fcml_st_mp_mnemonic_set *mnemonics_set;

    fcml_ceh_error error = fcml_fn_mp_parse_mnemonics( "cmps[sb,mm];cmpsw[ts,o*,aw,sf,mr];cmpsd[ts,o*,ad,sf];cmpsq[ts,o*,aq,sf]", &mnemonics_set );
    STF_ASSERT_EQUAL( error, FCML_CEH_GEC_NO_ERROR );

    fcml_st_coll_list_element *element = mnemonics_set->mnemonics->head;
    fcml_st_mp_mnemonic *mnemonic = (fcml_st_mp_mnemonic*)element->item;
    STF_ASSERT_STRING_EQUAL( mnemonic->mnemonic, "cmps" );
    STF_ASSERT_EQUAL( mnemonic->is_shortcut, FCML_FALSE );
    STF_ASSERT_EQUAL( mnemonic->supported_asa, FCML_DS_UNDEF );
    STF_ASSERT_EQUAL( mnemonic->supported_osa, FCML_DS_UNDEF );
    STF_ASSERT_EQUAL( mnemonic->is_byte_ds, FCML_TRUE );
    STF_ASSERT_EQUAL( mnemonic->is_full_ds, FCML_FALSE );
    STF_ASSERT_EQUAL( mnemonic->is_mode_mem_only, FCML_TRUE );
    STF_ASSERT_EQUAL( mnemonic->is_mode_reg_only, FCML_FALSE );

    element = element->next;
    mnemonic = (fcml_st_mp_mnemonic*)element->item;
    STF_ASSERT_STRING_EQUAL( mnemonic->mnemonic, "cmpsw" );
    STF_ASSERT_EQUAL( mnemonic->is_shortcut, FCML_TRUE );
    STF_ASSERT_EQUAL( mnemonic->supported_asa, FCML_DS_16 );
    STF_ASSERT_EQUAL( mnemonic->supported_osa, FCML_DS_UNDEF );
    STF_ASSERT_EQUAL( mnemonic->is_byte_ds, FCML_FALSE );
	STF_ASSERT_EQUAL( mnemonic->is_full_ds, FCML_TRUE );
	STF_ASSERT_EQUAL( mnemonic->is_mode_mem_only, FCML_FALSE );
	STF_ASSERT_EQUAL( mnemonic->is_mode_reg_only, FCML_TRUE );

    element = element->next;
    mnemonic = (fcml_st_mp_mnemonic*)element->item;
    STF_ASSERT_STRING_EQUAL( mnemonic->mnemonic, "cmpsd" );
    STF_ASSERT_EQUAL( mnemonic->is_shortcut, FCML_TRUE );
    STF_ASSERT_EQUAL( mnemonic->supported_asa, FCML_DS_32 );
    STF_ASSERT_EQUAL( mnemonic->supported_osa, FCML_DS_UNDEF );

    element = element->next;
    mnemonic = (fcml_st_mp_mnemonic*)element->item;
    STF_ASSERT_STRING_EQUAL( mnemonic->mnemonic, "cmpsq" );
    STF_ASSERT_EQUAL( mnemonic->is_shortcut, FCML_TRUE );
    STF_ASSERT_EQUAL( mnemonic->supported_asa, FCML_DS_64 );
    STF_ASSERT_EQUAL( mnemonic->supported_osa, FCML_DS_UNDEF );

    STF_ASSERT_PTR_NULL( element->next );

    fcml_fn_mp_free_mnemonics( mnemonics_set );
}

void fcml_tf_mnemonic_parser_test_parse_mnemonics_1(void) {

    fcml_st_mp_mnemonic_set *mnemonics_set;

    fcml_ceh_error error = fcml_fn_mp_parse_mnemonics( "cmps;", &mnemonics_set );
    STF_ASSERT_EQUAL( error, FCML_CEH_GEC_NO_ERROR );

    fcml_st_coll_list_element *element = mnemonics_set->mnemonics->head;
    fcml_st_mp_mnemonic *mnemonic = (fcml_st_mp_mnemonic*)element->item;
    STF_ASSERT_STRING_EQUAL( mnemonic->mnemonic, "cmps" );
    STF_ASSERT_EQUAL( mnemonic->is_shortcut, FCML_FALSE );
    STF_ASSERT_EQUAL( mnemonic->supported_asa, FCML_DS_UNDEF );
    STF_ASSERT_EQUAL( mnemonic->supported_osa, FCML_DS_UNDEF );

    STF_ASSERT_PTR_NULL( element->next );

    fcml_fn_mp_free_mnemonics( mnemonics_set );
}

void fcml_tf_mnemonic_parser_test_parse_mnemonics_2(void) {

    fcml_st_mp_mnemonic_set *mnemonics_set;

    fcml_ceh_error error = fcml_fn_mp_parse_mnemonics( "cmps[ts];", &mnemonics_set );
    STF_ASSERT_EQUAL( error, FCML_CEH_GEC_NO_ERROR );

    fcml_st_coll_list_element *element = mnemonics_set->mnemonics->head;
    fcml_st_mp_mnemonic *mnemonic = (fcml_st_mp_mnemonic*)element->item;
    STF_ASSERT_STRING_EQUAL( mnemonic->mnemonic, "cmps" );
    STF_ASSERT_EQUAL( mnemonic->is_shortcut, FCML_TRUE );
    STF_ASSERT_EQUAL( mnemonic->supported_asa, FCML_DS_UNDEF );
    STF_ASSERT_EQUAL( mnemonic->supported_osa, FCML_DS_UNDEF );

    STF_ASSERT_PTR_NULL( element->next );

    fcml_fn_mp_free_mnemonics( mnemonics_set );
}

fcml_string fcml_itb_bad_formatted_mnemonics[] = {
    "",
    ";",
    ";[",
    "[;",
    ";;;;",
    ";cmps",
    "cmps[;",
    "cmps[];",
    "cmps];",
    "cmps[[ts];",
    "cmps[ts]];",
    "cmps[ts;",
    "cmps[ts",
    "cmps[t",
    "cmps[t]",
    "cmps[bx]",
    "cmps[om]",
    "cm!ps",
    " cmps",
    "[]",
    "cmps[oda",
    "cmps]",
    "cmps[odadddf]",
    "cmps[od,,ad]",
    "cmps[,od]",
    "cmps[od,]",
    "cmps[,]",
    "cmps[,,]",
    "cmps[,",
    "cmps[ad;]",
};

void fcml_tf_mnemonic_parser_test_parse_mnemonics_3(void) {
    int i;
    for( i = 0; i < sizeof( fcml_itb_bad_formatted_mnemonics ) / sizeof( fcml_string ); i++ ) {
        fcml_st_mp_mnemonic_set *mnemonics_set = NULL;
        fcml_string mnemonic = fcml_itb_bad_formatted_mnemonics[i];
        fcml_ceh_error error = fcml_fn_mp_parse_mnemonics( mnemonic, &mnemonics_set );
       /* printf("%d:%d\n", i, error);*/
        STF_ASSERT_EQUAL( error, FCML_CEH_GEC_INVALID_INPUT );
        STF_ASSERT_PTR_NULL( mnemonics_set );
    }
}

void fcml_tf_mnemonic_parser_test_parse_mnemonics_4(void) {

    fcml_st_mp_mnemonic_set *mnemonics_set;

    fcml_ceh_error error = fcml_fn_mp_parse_mnemonics( "cmpordsd[p07]", &mnemonics_set );
    STF_ASSERT_EQUAL( error, FCML_CEH_GEC_NO_ERROR );

    fcml_st_coll_list_element *element = mnemonics_set->mnemonics->head;
    fcml_st_mp_mnemonic *mnemonic = (fcml_st_mp_mnemonic*)element->item;
    STF_ASSERT_STRING_EQUAL( mnemonic->mnemonic, "cmpordsd" );
    STF_ASSERT_EQUAL( mnemonic->is_shortcut, FCML_FALSE );
    STF_ASSERT_EQUAL( mnemonic->supported_asa, FCML_DS_UNDEF );
    STF_ASSERT_EQUAL( mnemonic->supported_osa, FCML_DS_UNDEF );
    STF_ASSERT_EQUAL( mnemonic->pseudo_op.is_not_null, FCML_TRUE );
    STF_ASSERT_EQUAL( mnemonic->pseudo_op.value, 0x07 );

    STF_ASSERT_PTR_NULL( element->next );

    fcml_fn_mp_free_mnemonics( mnemonics_set );
}

void fcml_tf_mnemonic_parser_test_parse_mnemonics_5(void) {

    fcml_st_mp_mnemonic_set *mnemonics_set;

    fcml_ceh_error error = fcml_fn_mp_parse_mnemonics( "cmpordsd[S07]", &mnemonics_set );
    STF_ASSERT_EQUAL( error, FCML_CEH_GEC_NO_ERROR );

    fcml_st_coll_list_element *element = mnemonics_set->mnemonics->head;
    fcml_st_mp_mnemonic *mnemonic = (fcml_st_mp_mnemonic*)element->item;
    STF_ASSERT_STRING_EQUAL( mnemonic->mnemonic, "cmpordsd" );
    STF_ASSERT_EQUAL( mnemonic->is_shortcut, FCML_FALSE );
    STF_ASSERT_EQUAL( mnemonic->supported_asa, FCML_DS_UNDEF );
    STF_ASSERT_EQUAL( mnemonic->supported_osa, FCML_DS_UNDEF );
    STF_ASSERT_EQUAL( mnemonic->suffix.is_not_null, FCML_TRUE );
    STF_ASSERT_EQUAL( mnemonic->suffix.value, 0x07 );

    STF_ASSERT_PTR_NULL( element->next );

    fcml_fn_mp_free_mnemonics( mnemonics_set );
}

fcml_stf_test_case fcml_ti_mnemonic_parser[] = {
	{ "fcml_tf_mnemonic_parser_test_parse_mnemonics", fcml_tf_mnemonic_parser_test_parse_mnemonics },
	{ "fcml_tf_mnemonic_parser_test_parse_mnemonics_1", fcml_tf_mnemonic_parser_test_parse_mnemonics_1 },
	{ "fcml_tf_mnemonic_parser_test_parse_mnemonics_2", fcml_tf_mnemonic_parser_test_parse_mnemonics_2 },
	{ "fcml_tf_mnemonic_parser_test_parse_mnemonics_3", fcml_tf_mnemonic_parser_test_parse_mnemonics_3 },
	{ "fcml_tf_mnemonic_parser_test_parse_mnemonics_4", fcml_tf_mnemonic_parser_test_parse_mnemonics_4 },
	{ "fcml_tf_mnemonic_parser_test_parse_mnemonics_5", fcml_tf_mnemonic_parser_test_parse_mnemonics_5 },
	FCML_STF_NULL_TEST
};

fcml_stf_test_suite fcml_si_mnemonic_parser = {
	"suite-fcml-mnemonic-parser", fcml_tf_mnemonic_parser_suite_init, fcml_tf_mnemonic_parser_suite_cleanup, fcml_ti_mnemonic_parser
};