BEGIN { use_ok(
'Parse::Liberty'
) };
sub
forall (&@) {
my
$expr
=
shift
;
my
@list
=
@_
;
foreach
(
@list
) {
return
0
if
!&{
$expr
} }
return
1;
}
sub
isa_all {
my
$str
=
shift
;
my
@list
=
@_
;
return
forall {
$_
->isa(
$str
)}
@list
;
}
my
$indent
= 4;
my
$file
=
"test.lib"
;
my
(
$attr
,
$def
,
$g
,
@vals
,
$val
);
my
$parser
= new Parse::Liberty (
verbose
=>0,
indent
=>
$indent
,
file
=>
$file
);
isa_ok(
$parser
,
'Parse::Liberty'
);
can_ok(
$parser
,
'new'
,
'methods'
,
'library'
);
ok(
$parser
->{file} eq
"test.lib"
,
"Parser 'file' property"
);
ok(
$parser
->{indent} == 4,
"Parser 'indent' property"
);
ok(
$parser
->{verbose} == 0,
"Parser 'verbose' property"
);
ok(
$parser
->methods eq
"library\nwrite_library\n"
,
"Parser methods"
);
my
$library
=
$parser
->library;
isa_ok(
$library
,
'Parse::Liberty::Group'
);
can_ok(
$library
,
'new'
,
'methods'
,
'lineno'
,
'comment'
,
'remove'
,
'type'
,
'get_names'
,
'set_names'
,
'get_attributes'
,
'get_defines'
,
'get_groups'
,
'extract'
);
ok(
$library
->{object_type} eq
'group'
,
"Library 'object_type' property"
);
isa_ok(
$library
->{parser},
'Parse::Liberty'
);
isa_ok(
$library
->{parent},
'Parse::Liberty'
);
isa_ok(
$library
->{si2_object},
'liberty::si2ObjectIdT'
);
ok(
$library
->{depth} == 0,
"Library 'depth' property"
);
ok(
$library
->methods eq
"lineno\ncomment\nremove\ntype\nget_names\nset_names\nget_attributes\nget_defines\nget_groups\nextract\n"
,
"Library methods"
);
ok(
$library
->lineno == 1,
"Library lineno"
);
ok(!
defined
$library
->comment,
"Library comment"
);
ok(
$library
->type eq
'library'
,
"Library type"
);
ok(
$library
->get_names eq
'test1'
,
"Library name"
);
ok(
$library
->set_names(
'testlib'
) == 1,
"Library set new name"
);
ok(
$library
->get_names eq
'testlib'
,
"Library get new name"
);
my
@attrs
;
@attrs
=
$library
->get_attributes;
ok(
$#attrs
== 8 && isa_all(
'Parse::Liberty::Attribute'
,
@attrs
),
"Library get all attributes"
);
@attrs
=
$library
->get_attributes(
'delay_model'
,
'FANOUT'
);
ok(
$#attrs
== 1 && isa_all(
'Parse::Liberty::Attribute'
,
@attrs
),
"Library get two attributes"
);
@attrs
=
$library
->get_attributes(
'FAN.*T'
,
'.*_unit'
);
ok(
$#attrs
== 4 && isa_all(
'Parse::Liberty::Attribute'
,
@attrs
),
"Library get attributes by regex"
);
$attr
=
$library
->get_attributes(
'technology'
);
ok(
$attr
->isa(
'Parse::Liberty::Attribute'
),
"Library get one attribute"
);
my
@defs
;
@defs
=
$library
->get_defines;
ok(
$#defs
== 3 && isa_all(
'Parse::Liberty::Define'
,
@defs
),
"Library get all defines"
);
@defs
=
$library
->get_defines(
'sec_acore_internal_power'
,
'sec_acore_when'
);
ok(
$#defs
== 1 && isa_all(
'Parse::Liberty::Define'
,
@defs
),
"Library get two defines"
);
@defs
=
$library
->get_defines(
'.*when.*'
,
'.*l_power'
);
ok(
$#defs
== 2 && isa_all(
'Parse::Liberty::Define'
,
@defs
),
"Library get defines by regex"
);
$def
=
$library
->get_defines(
'sec_acore_rise_power'
);
ok(
$def
->isa(
'Parse::Liberty::Define'
),
"Library get one define"
);
my
@gps
;
@gps
=
$library
->get_groups;
ok(
$#gps
== 5 && isa_all(
'Parse::Liberty::Group'
,
@gps
),
"Library get all groups"
);
@gps
=
$library
->get_groups(
'cell'
);
ok(
$#gps
== 4 && isa_all(
'Parse::Liberty::Group'
,
@gps
),
"Library get all groups by type"
);
@gps
=
$library
->get_groups(
'cell'
,
'cell5'
,
'cell2'
);
ok(
$#gps
== 1 && isa_all(
'Parse::Liberty::Group'
,
@gps
),
"Library get two groups by type and name"
);
@gps
=
$library
->get_groups(
'cell'
,
'c.*5'
,
'.*[1-3]'
);
ok(
$#gps
== 3 && isa_all(
'Parse::Liberty::Group'
,
@gps
),
"Library get groups by type and regex"
);
$g
=
$library
->get_groups(
'lu_table_template'
,
'dti_delay_drivex1_5x7'
);
ok(
$g
->isa(
'Parse::Liberty::Group'
),
"Library get one group by type and name"
);
$attr
=
$library
->get_attributes(
'nom_temperature'
);
isa_ok(
$attr
,
'Parse::Liberty::Attribute'
);
can_ok(
$attr
,
'new'
,
'methods'
,
'lineno'
,
'comment'
,
'remove'
,
'type'
,
'name'
,
'is_var'
,
'get_values'
,
'set_values'
,
'extract'
);
ok(
$attr
->{object_type} eq
'attribute'
,
"Attribute 'object_type' property"
);
isa_ok(
$attr
->{parser},
'Parse::Liberty'
);
isa_ok(
$attr
->{parent},
'Parse::Liberty::Group'
);
isa_ok(
$attr
->{si2_object},
'liberty::si2ObjectIdT'
);
ok(
$attr
->{depth} == 1,
"Attribute 'depth' property"
);
ok(
$attr
->methods eq
"lineno\ncomment\nremove\ntype\nname\nis_var\nget_values\nset_values\nextract\n"
,
"Attribute methods"
);
ok(
$attr
->lineno == 10,
"Attribute lineno"
);
ok(
$attr
->comment eq
'0'
,
"Attribute comment"
);
ok(
$attr
->type eq
'simple'
,
"Attribute type"
);
ok(
$attr
->name eq
'nom_temperature'
,
"Attribute name"
);
ok(
$attr
->is_var == 0,
"Simple attribute is not a variable declaration"
);
@vals
=
$attr
->get_values;
ok(
$#vals
== 0 &&
$vals
[0]->type eq
'integer'
&&
$vals
[0]->value == 25,
"Simple attribute get all values"
);
$val
=
$attr
->get_values;
ok(
$val
->type eq
'integer'
&&
$val
->value == 25,
"Simple attribute get first value"
);
ok(
$attr
->set_values(
'boolean'
, 0,
'string'
,
"abc"
,
'float'
, 1.23) == 1,
"Simple attribute set new values (always first value only)"
);
@vals
=
$attr
->get_values;
ok(
$#vals
== 0 # but
'get'
on boolean value give
'false'
or
'true'
as in .lib
&&
$vals
[0]->type eq
'boolean'
&&
$vals
[0]->value eq
'false'
,
"Simple attribute get new value"
);
ok(
$attr
->extract eq
"/*0*/\n"
.
' '
x
$indent
.
"nom_temperature : false ;\n"
,
"Simple attribute extract"
);
$attr
=
$library
->get_attributes(
'capacitive_load_unit'
);
ok(
$attr
->is_var == 0,
"Complex attribute cannot be a variable declaration"
);
@vals
=
$attr
->get_values;
ok(
$#vals
== 1
&&
$vals
[0]->type eq
'integer'
&&
$vals
[0]->value == 1
&&
$vals
[1]->type eq
'string'
&&
$vals
[1]->value eq
"pf"
,
"Complex attribute get all values"
);
$val
=
$attr
->get_values;
ok(
$val
->type eq
'integer'
&&
$val
->value == 1,
"Complex attribute get first value"
);
ok(
$attr
->set_values(
'boolean'
, 0,
'string'
,
"abc"
,
'float'
, 1.23) == 1,
"Complex attribute set new values"
);
@vals
=
$attr
->get_values;
ok(
$#vals
== 2
&&
$vals
[0]->type eq
'boolean'
&&
$vals
[0]->value eq
'false'
&&
$vals
[1]->type eq
'string'
&&
$vals
[1]->value eq
"abc"
&&
$vals
[2]->type eq
'float'
&&
$vals
[2]->value == 1.23,
"Complex attribute get new values"
);
ok(
$attr
->extract eq
' '
x
$indent
.
"capacitive_load_unit (false, abc, 1.23) ;\n"
,
"Complex attribute extract"
);
$attr
=
$library
->get_attributes(
'FANOUT'
);
ok(
$attr
->is_var == 1,
"Simple variable attribute is variable declaration"
);
@vals
=
$attr
->get_values;
ok(
$#vals
== 0
&&
$vals
[0]->type eq
'integer'
&&
$vals
[0]->value == 5,
"Simple variable attribute get all values"
);
$val
=
$attr
->get_values;
ok(
$val
->type eq
'integer'
&&
$val
->value == 5,
"Simple variable attribute get first value"
);
ok(
$attr
->set_values(
'boolean'
, 0,
'string'
,
"abc"
,
'float'
, 1.23) == 1,
"Simple variable attribute set new values (always first value only)"
);
@vals
=
$attr
->get_values;
ok(
$#vals
== 0
&&
$vals
[0]->type eq
'boolean'
&&
$vals
[0]->value eq
'false'
,
"Simple variable attribute get new value"
);
ok(
$attr
->extract eq
' '
x
$indent
.
"FANOUT = false ;\n"
,
"Simple variable attribute extract"
);
ok(
$attr
->remove == 1 && !
defined
$library
->get_attributes(
'FANOUT'
),
"Attribute remove"
);
$def
=
$library
->get_defines(
'sec_acore_rise_power'
);
isa_ok(
$def
,
'Parse::Liberty::Define'
);
can_ok(
$def
,
'new'
,
'methods'
,
'lineno'
,
'comment'
,
'remove'
,
'type'
,
'name'
,
'allowed_group_name'
,
'extract'
);
ok(
$def
->{object_type} eq
'define'
,
"Define 'object_type' property"
);
isa_ok(
$def
->{parser},
'Parse::Liberty'
);
isa_ok(
$def
->{parent},
'Parse::Liberty::Group'
);
isa_ok(
$def
->{si2_object},
'liberty::si2ObjectIdT'
);
ok(
$def
->{depth} == 1,
"Define 'depth' property"
);
ok(
$def
->methods eq
"lineno\ncomment\nremove\ntype\nname\nallowed_group_name\nextract\n"
,
"Define methods"
);
ok(
$def
->lineno == 15,
"Define lineno"
);
ok(!
defined
$def
->comment,
"Define comment"
);
ok(
$def
->type eq
'float'
,
"Define type"
);
ok(
$def
->name eq
'sec_acore_rise_power'
,
"Define name"
);
ok(
$def
->allowed_group_name eq
'sec_acore_internal_power'
,
"Define allowed group name"
);
ok(
$def
->extract eq
' '
x
$indent
.
"define (sec_acore_rise_power, sec_acore_internal_power, float) ;\n"
,
"Define extract"
);
ok(
$def
->remove == 1 && !
defined
$library
->get_defines(
'sec_acore_rise_power'
),
"Define remove"
);
$attr
=
$library
->get_attributes(
'default_max_transition'
);
$val
=
$attr
->get_values;
isa_ok(
$val
,
'Parse::Liberty::Value'
);
can_ok(
$val
,
'new'
,
'methods'
,
'type'
,
'value'
);
ok(
$val
->{object_type} eq
'value'
,
"Value 'object_type' property"
);
isa_ok(
$val
->{parser},
'Parse::Liberty'
);
isa_ok(
$val
->{parent},
'Parse::Liberty::Attribute'
);
ok(!
defined
$val
->{si2_object},
"Simple attribute value 'si2_object' property (always undefined)"
);
ok(
$val
->type eq
'float'
,
"Simple attribute value type"
);
ok(
$val
->value == 2.4,
"Simple attribute value value"
);
$attr
=
$library
->get_attributes(
'technology'
);
$val
=
$attr
->get_values;
isa_ok(
$val
->{si2_object},
'_p_si2drAttrComplexValIdT'
);
ok(
$val
->type eq
'string'
,
"Complex attribute value type"
);
ok(
$val
->value eq
"cmos"
,
"Complex attribute value value"
);
ok(
$val
->methods eq
"type\nvalue\n"
,
"Value methods"
);
my
$cell
=
$library
->get_groups(
'cell'
,
'cell2'
);
ok(
$cell
->extract eq
"/* cell */\n"
.
' '
x
$indent
.
"cell (cell2) {\n"
.
' '
x 2 x
$indent
.
"area : 777.88 ;\n"
.
' '
x
$indent
.
"}\n"
,
"Group extract"
);
ok(
$cell
->remove == 1,
"Group remove"
);
ok(
$library
->extract eq
join
(
''
, <DATA>),
"Extract full library "
);