1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
10
* Sun Industry Standards Source License Version 1.2
11
* =================================================
12
* The contents of this file are subject to the Sun Industry Standards
13
* Source License Version 1.2 (the "License"); You may not use this file
14
* except in compliance with the License. You may obtain a copy of the
15
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
17
* Software provided under this License is provided on an "AS IS" basis,
18
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
19
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
20
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
21
* See the License for the specific provisions governing your rights and
22
* obligations concerning the Software.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
33
#include "sge_all_listsL.h"
35
#include "sge_bootstrap.h"
36
#include "sge_hgroup.h"
38
#include "sge_userset.h"
39
#include "sge_resource_quota.h"
56
int main(int argc, char *argv[])
58
int pos_tests_failed = 0;
59
int neg_tests_failed = 0;
63
filter_test_t positiv_test[] = {
65
{{"user1,user2,user3", NULL, NULL, NULL, NULL, NULL}, {"user3", "staff", "*", "*", "*", "*"}, false},
66
{{NULL, NULL, "project1,project2,project3", NULL, NULL, NULL}, {"*", "staff", "project2", "*", "*", "*"}, false},
67
{{NULL, NULL, NULL, "pe1,pe2,pe3", NULL, NULL}, {"*", "staff", "*", "pe3", "*", "*"}, false},
68
{{NULL, NULL, NULL, NULL, "h1,h2,h3", NULL}, {"*", "staff", "*", "*", "h3", "*"}, false},
69
{{NULL, NULL, NULL, NULL, NULL, "queue1,queue2,queue3"}, {"*", "staff", "*", "*", "*", "queue1"}, false},
71
{{"user1,user2,user3", NULL, NULL, NULL, NULL, NULL}, {"user*", "*", "staff", "*", "*", "*"}, false},
72
{{NULL, NULL, "project1,project2,project3", NULL, NULL, NULL}, {"*", "staff", "project*", "*", "*", "*"}, false},
73
{{NULL, NULL, NULL, "pe1,pe2,pe3", NULL, NULL}, {"*", "staff", "*", "pe*", "*", "*"}, false},
74
{{NULL, NULL, NULL, NULL, "h1,h2,h3", NULL}, {"*", "staff", "*", "*", "h*", "*"}, false},
75
{{NULL, NULL, NULL, NULL, NULL, "queue1,queue2,queue3"}, {"*", "staff", "*", "*", "*", "que*"}, false},
76
/* wildcard definition */
77
{{"user*", NULL, NULL, NULL, NULL, NULL}, {"user3", "staff", "*", "*", "*", "*"}, false},
78
{{NULL, NULL, "project*", NULL, NULL, NULL}, {"*", "staff", "project2", "*", "*", "*"}, false},
79
{{NULL, NULL, NULL, "pe*", NULL, NULL}, {"*", "staff", "*", "pe3", "*", "*"}, false},
80
{{NULL, NULL, NULL, NULL, "h*", NULL}, {"*", "staff", "*", "*", "h1", "*"}, false},
81
{{NULL, NULL, NULL, NULL, NULL, "queue*"}, {"*", "staff", "*", "*", "*", "queue1"}, false},
82
/* wildcard definition, wildcard search */
83
{{"user*", NULL, NULL, NULL, NULL, NULL}, {"u*", "staff", "*", "*", "*", "*"}, false},
84
{{NULL, NULL, "project*", NULL, NULL, NULL}, {"*", "staff", "pro*", "*", "*", "*"}, false},
85
{{NULL, NULL, NULL, "pe*", NULL, NULL}, {"*", "staff", "*", "p*", "*", "*"}, false},
86
{{NULL, NULL, NULL, NULL, "host*", NULL}, {"*", "staff", "*", "*", "h*", "*"}, false},
87
{{NULL, NULL, NULL, NULL, NULL, "queue*"}, {"*", "staff", "*", "*", "*", "qu*"}, false},
88
/* hostgroup definition*/
89
{{NULL, NULL, NULL, NULL, "@hgrp1", NULL}, {"*", "staff", "*", "*", "host1", "*"}, false},
90
{{NULL, NULL, NULL, NULL, "@hgrp1", NULL}, {"*", "staff", "*", "*", "ho*", "*"}, false},
91
{{NULL, NULL, NULL, NULL, "@hgr*", NULL}, {"*", "staff", "*", "*", "host1", "*"}, false},
92
{{NULL, NULL, NULL, NULL, "@hgr*", NULL}, {"*", "staff", "*", "*", "hos*", "*"}, false},
93
{{NULL, NULL, NULL, NULL, "@hgrp1", NULL}, {"*", "staff", "*", "*", "@hgrp1", "*"}, false},
94
{{NULL, NULL, NULL, NULL, "host1", NULL}, {"*", "staff", "*", "*", "@hgrp1", "*"}, false},
95
{{NULL, NULL, NULL, NULL, "ho*", NULL}, {"*", "staff", "*", "*", "@hgrp1", "*"}, false},
96
{{NULL, NULL, NULL, NULL, "host1", NULL}, {"*", "staff", "*", "*", "@hgrp*", "*"}, false},
97
{{NULL, NULL, NULL, NULL, "ho*", NULL}, {"*", "staff", "*", "*", "@hgrp*", "*"}, false},
98
{{NULL, NULL, NULL, NULL, "ho*", NULL}, {"*", "staff", "*", "*", "*", "*"}, false},
99
{{NULL, NULL, NULL, NULL, "!@hgrp1", NULL}, {"*", "staff", "*", "*", "*", "*"}, false},
100
{{NULL, NULL, NULL, NULL, "!@hgrp1", NULL}, {"*", "staff", "*", "*", "@hgrp*", "*"}, false},
101
/* userset definition */
102
{{"@userset1", NULL, NULL, NULL, NULL, NULL}, {"user1", "staff", "*", "*", "*", "*"}, false},
103
{{"@userset1", NULL, NULL, NULL, NULL, NULL}, {"use*", "staff", "*", "*", "*", "*"}, false},
104
{{"@users*", NULL, NULL, NULL, NULL, NULL}, {"user1", "staff", "*", "*", "*", "*"}, false},
105
{{"@users*", NULL, NULL, NULL, NULL, NULL}, {"user*", "staff", "*", "*", "*", "*"}, false},
106
{{"user1", NULL, NULL, NULL, NULL, NULL}, {"@userset1", "staff", "*", "*", "*", "*"}, false},
107
{{"us*", NULL, NULL, NULL, NULL, NULL}, {"@userset1", "staff", "*", "*", "*", "*"}, false},
108
{{"user1", NULL, NULL, NULL, NULL, NULL}, {"@use*", "staff", "*", "*", "*", "*"}, false},
109
{{"use*", NULL, NULL, NULL, NULL, NULL}, {"@use*", "staff", "*", "*", "*", "*"}, false},
110
{{"@user*2", NULL, NULL, NULL, NULL, NULL}, {"user1", "staff", "*", "*", "*", "*"}, false},
111
{{"@user*2", NULL, NULL, NULL, NULL, NULL}, {"user1", "*", "*", "*", "*", "*"}, false},
112
{{"!@user*", NULL, NULL, NULL, NULL, NULL}, {"*", "*", "*", "*", "*", "*"}, false},
113
/* project definition */
114
{{NULL, NULL, "!*", NULL, NULL, NULL}, {"*", "staff", NULL, "*", "*", "*"}, false},
116
{{NULL, NULL, NULL, NULL, NULL, NULL}, {"*", "staff", "*", "*", "*", "*"}, true},
119
filter_test_t negativ_test[] = {
121
{{"*,!user3", NULL, NULL, NULL, NULL, NULL}, {"user3", "staff", "*", "*", "*", "*"}, false},
122
{{"user1,user2", NULL, NULL, NULL, NULL, NULL}, {"user3", "staff", "*", "*", "*", "*"}, false},
123
{{NULL, NULL, "*,!project2", NULL, NULL, NULL}, {"*", "staff", "project2", "*", "*", "*"}, false},
124
{{NULL, NULL, "project1,project3", NULL, NULL, NULL}, {"*", "staff", "project2", "*", "*", "*"}, false},
125
{{NULL, NULL, NULL, "*,!pe3", NULL, NULL}, {"*", "staff", "*", "pe3", "*", "*"}, false},
126
{{NULL, NULL, NULL, "pe1,pe2", NULL, NULL}, {"*", "staff", "*", "pe3", "*", "*"}, false},
127
{{NULL, NULL, NULL, NULL, "*,!h3", NULL}, {"*", "staff", "*", "*", "h3", "*"}, false},
128
{{NULL, NULL, NULL, NULL, "h1,h2", NULL}, {"*", "staff", "*", "*", "h3", "*"}, false},
129
{{NULL, NULL, NULL, NULL, NULL, "*,!queue1"}, {"*", "staff", "*", "*", "*", "queue1"}, false},
130
{{NULL, NULL, NULL, NULL, NULL, "queue2,queue3"}, {"*", "staff", "*", "*", "*", "queue1"}, false},
131
/* wildcard definition, wildcard search */
132
{{"!us*", NULL, NULL, NULL, NULL, NULL}, {"user*", "staff", "*", "*", "*", "*"}, false},
133
{{NULL, NULL, "!pro*", NULL, NULL, NULL}, {"*", "staff", "project*", "*", "*", "*"}, false},
134
{{NULL, NULL, NULL, "!p*", NULL, NULL}, {"*", "staff", "*", "pe*", "*", "*"}, false},
135
{{NULL, NULL, NULL, NULL, "!h*", NULL}, {"*", "staff", "*", "*", "hos*", "*"}, false},
136
{{NULL, NULL, NULL, NULL, NULL, "!qu*"}, {"*", "staff", "*", "*", "*", "que*"}, false},
137
/* hostgroup definition*/
138
{{NULL, NULL, NULL, NULL, "!@hgrp1", NULL}, {"*", "staff", "*", "*", "host1", "*"}, false},
139
{{NULL, NULL, NULL, NULL, "!@hgrp1", NULL}, {"*", "staff", "*", "*", "ho*", "*"}, false},
140
{{NULL, NULL, NULL, NULL, "!@hgr*", NULL}, {"*", "staff", "*", "*", "host1", "*"}, false},
141
{{NULL, NULL, NULL, NULL, "!@hgr*", NULL}, {"*", "staff", "*", "*", "hos*", "*"}, false},
142
{{NULL, NULL, NULL, NULL, "!hgrp1", NULL}, {"*", "staff", "*", "*", "hgrp1", "*"}, false},
143
{{NULL, NULL, NULL, NULL, "!hgrp*", NULL}, {"*", "staff", "*", "*", "hgrp*", "*"}, false},
144
/* userset definition */
145
{{"!@userset1", NULL, NULL, NULL, NULL, NULL}, {"user1", "staff", "*", "*", "*", "*"}, false},
146
{{"!@userset1", NULL, NULL, NULL, NULL, NULL}, {"use*", "staff", "*", "*", "*", "*"}, false},
147
{{"!@users*", NULL, NULL, NULL, NULL, NULL}, {"user1", "staff", "*", "*", "*", "*"}, false},
148
{{"!@users*", NULL, NULL, NULL, NULL, NULL}, {"user*", "staff", "*", "*", "*", "*"}, false},
149
{{"!@userset2", NULL, NULL, NULL, NULL, NULL}, {"user1", "staff", "*", "*", "*", "*"}, false},
150
{{"@userset1,!@userset2", NULL, NULL, NULL, NULL, NULL}, {"user1", "staff", "*", "*", "*", "*"}, false},
151
{{"@user*2", NULL, NULL, NULL, NULL, NULL}, {"user1", NULL, "*", "*", "*", "*"}, false},
152
/* project definition */
153
{{NULL, NULL, "*", NULL, NULL, NULL}, {"*", "staff", NULL, "*", "*", "*"}, false},
154
{{NULL, NULL, "!*", NULL, NULL, NULL}, {"*", "staff", "project1", "*", "*", "*"}, false},
156
{{"!*", NULL, NULL, NULL, NULL, NULL}, {"*", "staff", "*", "*", "*", "*"}, true},
164
DENTER_MAIN(TOP_LAYER, "test_sge_resouce_quota");
170
hgroup_list = lCreateList("" , HGRP_Type);
171
hgroup = lCreateElem(HGRP_Type);
172
lSetHost(hgroup, HGRP_name, "@hgrp1");
173
lAddSubHost(hgroup, HR_name, "host1", HGRP_host_list, HR_Type);
174
lAppendElem(hgroup_list, hgroup);
175
hgroup = lCreateElem(HGRP_Type);
176
lSetHost(hgroup, HGRP_name, "@hgrp2");
177
lAddSubHost(hgroup, HR_name, "host2", HGRP_host_list, HR_Type);
178
lAppendElem(hgroup_list, hgroup);
180
userset_list = lCreateList("", US_Type);
181
userset = lCreateElem(US_Type);
182
lSetString(userset, US_name, "userset1");
183
lAddSubStr(userset, UE_name, "user1", US_entries, UE_Type);
184
lAppendElem(userset_list, userset);
185
userset = lCreateElem(US_Type);
186
lSetString(userset, US_name, "userset2");
187
lAddSubStr(userset, UE_name, "@staff", US_entries, UE_Type);
188
lAppendElem(userset_list, userset);
191
lListElem *rule = lCreateElem(RQR_Type);
192
filter_t rule_filter = positiv_test[i].rule;
193
filter_t query_filter = positiv_test[i].query;
195
if (rqs_parse_filter_from_string(&filter, rule_filter.users, NULL)) {
196
lSetObject(rule, RQR_filter_users, filter);
198
if (rqs_parse_filter_from_string(&filter, rule_filter.projects, NULL)) {
199
lSetObject(rule, RQR_filter_projects, filter);
201
if (rqs_parse_filter_from_string(&filter, rule_filter.pes, NULL)) {
202
lSetObject(rule, RQR_filter_pes, filter);
204
if (rqs_parse_filter_from_string(&filter, rule_filter.hosts, NULL)) {
205
lSetObject(rule, RQR_filter_hosts, filter);
207
if (rqs_parse_filter_from_string(&filter, rule_filter.queues, NULL)) {
208
lSetObject(rule, RQR_filter_queues, filter);
210
if(!rqs_is_matching_rule(rule, query_filter.users, query_filter.group, query_filter.projects,
211
query_filter.pes, query_filter.hosts, query_filter.queues,
212
userset_list, hgroup_list)) {
213
printf("positiv filter matching failed (test %d)\n", i+1);
216
if (positiv_test[i].last == true) {
221
printf("%d positiv test(s) failed\n", pos_tests_failed);
224
lListElem *rule = lCreateElem(RQR_Type);
225
filter_t rule_filter = negativ_test[i].rule;
226
filter_t query_filter = negativ_test[i].query;
228
if (rqs_parse_filter_from_string(&filter, rule_filter.users, NULL)) {
229
lSetObject(rule, RQR_filter_users, filter);
231
if (rqs_parse_filter_from_string(&filter, rule_filter.projects, NULL)) {
232
lSetObject(rule, RQR_filter_projects, filter);
234
if (rqs_parse_filter_from_string(&filter, rule_filter.pes, NULL)) {
235
lSetObject(rule, RQR_filter_pes, filter);
237
if (rqs_parse_filter_from_string(&filter, rule_filter.hosts, NULL)) {
238
lSetObject(rule, RQR_filter_hosts, filter);
240
if (rqs_parse_filter_from_string(&filter, rule_filter.queues, NULL)) {
241
lSetObject(rule, RQR_filter_queues, filter);
243
if (rqs_is_matching_rule(rule, query_filter.users, query_filter.group, query_filter.projects,
244
query_filter.pes, query_filter.hosts, query_filter.queues,
245
userset_list, hgroup_list)) {
246
printf("negativ filter matching failed (test %d)\n", i+1);
253
if (negativ_test[i].last == true) {
258
printf("%d negativ test(s) failed\n", neg_tests_failed);
260
lFreeList(&hgroup_list);
261
lFreeList(&userset_list);
263
DRETURN(pos_tests_failed + neg_tests_failed);