mirror of
https://github.com/JakeHillion/drgn.git
synced 2024-12-23 09:43:06 +00:00
75c3679147
The current mixed Python/C implementation works well, but it has a couple of important limitations: - It's too slow for some common use cases, like iterating over large data structures. - It can't be reused in utilities written in other languages. This replaces the internals with a new library written in C, libdrgn. It includes Python bindings with mostly the same public interface as before, with some important improvements: - Types are now represented by a single Type class rather than the messy polymorphism in the Python implementation. - Qualifiers are a bitmask instead of a set of strings. - Bit fields are not considered a separate type. - The lvalue/rvalue terminology is replaced with reference/value. - Structure, union, and array values are better supported. - Function objects are supported. - Program distinguishes between lookups of variables, constants, and functions. The C rewrite is about 6x as fast as the original Python when using the Python bindings, and about 8x when using the C API directly. Currently, the exposed API in C is fairly conservative. In the future, the memory reader, type index, and object index APIs will probably be exposed for more flexibility.
31 lines
1000 B
Python
31 lines
1000 B
Python
import unittest
|
|
|
|
from tests.libdrgn import drgn_test_lexer_func, Lexer
|
|
|
|
|
|
class TestLexer(unittest.TestCase):
|
|
def test_pop(self):
|
|
lexer = Lexer(drgn_test_lexer_func, '12345')
|
|
for i in range(5):
|
|
self.assertEqual(lexer.pop().kind, ord('1') + i)
|
|
self.assertEqual(lexer.pop().kind, 0)
|
|
|
|
def test_push(self):
|
|
lexer = Lexer(drgn_test_lexer_func, '12345')
|
|
tokens = []
|
|
for i in range(4):
|
|
tokens.append(lexer.pop())
|
|
while tokens:
|
|
lexer.push(tokens.pop())
|
|
for i in range(5):
|
|
self.assertEqual(lexer.pop().kind, ord('1') + i)
|
|
self.assertEqual(lexer.pop().kind, 0)
|
|
|
|
def test_peek(self):
|
|
lexer = Lexer(drgn_test_lexer_func, '12345')
|
|
for i in range(5):
|
|
self.assertEqual(lexer.peek().kind, ord('1') + i)
|
|
self.assertEqual(lexer.pop().kind, ord('1') + i)
|
|
self.assertEqual(lexer.peek().kind, 0)
|
|
self.assertEqual(lexer.pop().kind, 0)
|