예제 #1
0
 def test_parameter_invalid_attribute_expression(self):
   textproto = ('host_calls { name: "strlen" return_type: "int" '
                'parameters { name: "s" type: "const char *" '
                'pointer_attributes { attribute: SIZE '
                'attribute_expression: "s" }}} ')
   with self.assertRaises(ValueError):
     code_generator.get_host_calls_dictionary(textproto)
예제 #2
0
 def test_parameter_conflicting_copy_attributes(self):
   textproto = ('host_calls { name: "strlen" return_type: "int" '
                'parameters { name: "s" type: "const char *" '
                'pointer_attributes { attribute: IN } '
                'pointer_attributes { attribute: USER_CHECK }}}')
   with self.assertRaises(ValueError):
     code_generator.get_host_calls_dictionary(textproto)
예제 #3
0
 def test_parameter_duplicate_pointer_attributes(self):
   textproto = ('host_calls { name: "strlen" return_type: "int" '
                'parameters { name: "s" type: "const char *" '
                'pointer_attributes { attribute: STRING } '
                'pointer_attributes { attribute: STRING }}}')
   with self.assertRaises(ValueError):
     code_generator.get_host_calls_dictionary(textproto)
예제 #4
0
 def test_host_call_no_parameters(self):
   getpid_textproto = 'host_calls { name: "getpid" return_type: "pid_t" }'
   host_calls = code_generator.get_host_calls_dictionary(getpid_textproto)
   getpid_parameters = _get_parameters_proto(host_calls)
   self.assertEqual(
       '', code_generator.comma_separate_parameters(getpid_parameters))
   self.assertEqual('',
                    code_generator.comma_separate_arguments(getpid_parameters))
예제 #5
0
 def test_host_call_one_parameter(self):
   fsync_textproto = ('host_calls { name: "fsync" return_type: "int" '
                      'parameters { name: "fd" type: "int" }}')
   host_calls = code_generator.get_host_calls_dictionary(fsync_textproto)
   fsync_parameters = _get_parameters_proto(host_calls)
   self.assertEqual(
       'int fd', code_generator.comma_separate_parameters(fsync_parameters))
   self.assertEqual(
       'fd', code_generator.comma_separate_arguments(fsync_parameters))
예제 #6
0
 def test_host_call_multiple_parameters(self):
   shutdown_textproto = ('host_calls { name: "shutdown" return_type: "int" '
                         'parameters { name: "sockfd" type: "int" } '
                         'parameters { name: "how" type: "int" }}')
   host_calls = code_generator.get_host_calls_dictionary(shutdown_textproto)
   shutdown_parameters = _get_parameters_proto(host_calls)
   self.assertEqual(
       'int sockfd, int how',
       code_generator.comma_separate_parameters(shutdown_parameters))
   self.assertEqual(
       'sockfd, how',
       code_generator.comma_separate_arguments(shutdown_parameters))
예제 #7
0
 def test_host_call_parameters_with_string_annotations(self):
   read_textproto = ('host_calls { name: "read" return_type: "int" '
                     'parameters { name: "path" type: "const char *" '
                     'pointer_attributes { attribute: IN } '
                     'pointer_attributes { attribute: STRING }} '
                     'parameters { name: "owner" type: "uint32_t" } '
                     'parameters { name: "group" type: "uint32_t" }}')
   host_calls = code_generator.get_host_calls_dictionary(read_textproto)
   read_parameters = _get_parameters_proto(host_calls)
   self.assertEqual(
       'const char * path, uint32_t owner, uint32_t group',
       code_generator.comma_separate_parameters(read_parameters))
   self.assertEqual(
       'path, owner, group',
       code_generator.comma_separate_arguments(read_parameters))
   self.assertEqual(
       '[in, string] const char * path, uint32_t owner, uint32_t group',
       code_generator.comma_separate_bridge_parameters(read_parameters))
예제 #8
0
 def test_host_call_parameters_with_size_annotations(self):
   chown_textproto = ('host_calls { name: "read" return_type: "int32_t" '
                      'parameters { name: "fd" type: "int" } '
                      'parameters { name: "buf1" type: "void *" '
                      'pointer_attributes { attribute: OUT } '
                      'pointer_attributes { attribute: SIZE '
                      'attribute_expression: "100" }} '
                      'parameters { name: "buf2" type: "void *" '
                      'pointer_attributes { attribute: OUT } '
                      'pointer_attributes { attribute: SIZE '
                      'attribute_expression: "len" }} '
                      'parameters { name: "len" type: "size_t" }}')
   host_calls = code_generator.get_host_calls_dictionary(chown_textproto)
   chown_parameters = _get_parameters_proto(host_calls)
   self.assertEqual(
       'int fd, void * buf1, void * buf2, size_t len',
       code_generator.comma_separate_parameters(chown_parameters))
   self.assertEqual(
       'fd, buf1, buf2, len',
       code_generator.comma_separate_arguments(chown_parameters))
   self.assertEqual(
       'int fd, [out, size=100] void * buf1, [out, size=len] void * buf2, '
       'size_t len',
       code_generator.comma_separate_bridge_parameters(chown_parameters))
예제 #9
0
 def test_host_call_missing_required_field(self):
   missing_type_textproto = ('host_calls { name: "fsync" return_type: "int" '
                             'parameters { name: "fd" }}')
   with self.assertRaises(ValueError):
     code_generator.get_host_calls_dictionary(missing_type_textproto)
예제 #10
0
 def test_host_call_invalid_textproto(self):
   invalid_textproto = 'unknown_proto { unknown_field: "unknown_value" }'
   with self.assertRaises(text_format.ParseError):
     code_generator.get_host_calls_dictionary(invalid_textproto)
예제 #11
0
 def test_parameter_missing_pointer_attributes(self):
   textproto = ('host_calls { name: "strlen" return_type: "int" '
                'parameters { name: "s" type: "int *" }}')
   with self.assertRaises(ValueError):
     code_generator.get_host_calls_dictionary(textproto)