Commit graph

779 commits

Author SHA1 Message Date
Peter Hutterer
3d3b20f172 doc: add the templates and a script to generate hugo markdown
Intention here is to have the protocol in a readable manner somewhere.
Doxygen doesn't *quite* cut the bill.
2023-03-03 15:24:42 +10:00
Peter Hutterer
eb9fa07c10 scanner: add a filter to escape ei protocol names
By default escape them with backticks for markdown
2023-03-03 11:39:03 +10:00
Peter Hutterer
2fb1ff70e3 scanner: allow '-' for loading a template from stdin 2023-03-03 11:39:03 +10:00
Peter Hutterer
ea3ada1a80 proto: make the documentation an extractable set of XML tags
Instead of hiding this in a XML comment, let's make it a proper set of
tags so we can extract it and use it in generated documentation.
2023-03-03 11:38:40 +10:00
Peter Hutterer
c350ac2ee3 src: pass the headerfile as jinja extra data
This removes another special handling of the C bindings from the
scanner.
2023-03-03 11:38:40 +10:00
Peter Hutterer
d127f02f0a scanner: add ability to pass extra data to the jinja templates
This makes generation of files with the scanner a lot more flexible -
e.g. one can run the scanner with
  --jinja-extra-data='{ "interface": "ei_connection"}'
and then in the jinja template use an if condition to match on this
interface.
2023-03-03 11:38:40 +10:00
Peter Hutterer
2fa7792a33 scanner: drop duplicate import
We already import dedent globally
2023-03-03 11:27:01 +10:00
Peter Hutterer
2550a0b54d scanner: raise SystemExit instead of calling sys.exit
Bit nicer (no import sys required for that call) and that's what sys.exit
does that anyway.
2023-03-03 11:27:01 +10:00
Peter Hutterer
70e2a9fbc2 protocol: fix two cross-references 2023-03-03 11:27:01 +10:00
Peter Hutterer
5f9bfe7b7b client: drop seats when destroying the client
This *should* have happened when the client got disconnected but in some
race conditions a seat may be added after the client gets disconnected.
Reproducible (sometimes) by test_invalid_object_id with the
eis-demo-server:
- client connects, sends invalid object ID, gets disconnected
- server sees CONNECTED, adds a seat, then sees DISCONNECTED and drops
  the client.

From the demo-server's POV the seat is handled by the client, so it
expects the client to destroy it.
2023-03-03 11:27:01 +10:00
Peter Hutterer
3c589f1b20 test: log all function calls to interfaces
Makes debugging easier to see exactly who's being called.
2023-03-03 11:27:01 +10:00
Peter Hutterer
59542a1ba0 test: group 4 bytes at a time in our hexlify function
Our protocol is groups of 4s, so make it easier to find individual items
in the hexdump.
2023-03-03 11:27:01 +10:00
Peter Hutterer
9700a47473 test: run pytest with xdist where available
A lot of the protocol tests have enforced timeouts because we need to
wait for the server to do something (or not). Running the protocol tests
with xdist means we can run those in parallel, which on my local box
roughly halves the time required to run all protocol tests.

Of course, this is all terrible. The only way to tell pytest to use
xdist is with `pytest -n <jobcount>`. But -n is only available if xdist
is installed. Dynamically adding commandline options is supposed to
be possible with `pytest_load_initial_conftests` in conftest.py, but
that doesn't actually work unless we're configuring a setuptool plugin.
Which we don't. What would work is `pytest_cmdline_preparse` but that
has been deprecated.

So we work around this by having meson check if xdist is available and
append `-n auto` for us.

In the CI let's be nice and only use the FDI_CI_CONCURRENT number of
jobs rather than hogging everything available. And, continuation from
"all is terrible": pytest complains if you have a hook that's unknown.
So if xdist is not available, you must not have the hook in conftest.py.
Which means we have to do it within an import + ImportError clause.

But yay, now we're saving literally seconds!
2023-03-03 11:27:01 +10:00
Peter Hutterer
bbc64b2eff CI: explicitly add ei-proto to the ruff check 2023-03-03 11:27:01 +10:00
Peter Hutterer
ba8bead183 meson.build: add black and ruff checks to the test suite
We still have the separate CI jobs for those (for better visibility) but
also optionally incorporate those into the meson test run.

Both calls only check the files, they do not modify anything.
2023-03-03 11:27:01 +10:00
Peter Hutterer
a806968ec5 test: up the timeout for dispatch
10ms isn't enough, esp. when running under valgrind
2023-03-03 11:27:01 +10:00
Peter Hutterer
037e092b62 test: throw an exception if sock.connect fails
We don't want to drop the error here, we need to see why something
failed.
2023-03-03 11:27:01 +10:00
Peter Hutterer
9b390f5703 eis: don't send a disconnected event when the client requests disconnect
As the protocol spec says, EIS should treat this as already disconnected
and not touch the connection.

This fixes a memleak if a client connects and immediately disconnects -
when EIS processes the EIS_EVENT_CLIENT_CONNECT it may set up a bunch of
things like seats (the eis-demo-server does this). Then, later, when
the EIS_EVENTE_CLIENT_DISCONNECT is processed, it calls
eis_client_disconnect() but we were already in the disconnected state
and the seats would not get released.
2023-03-03 11:27:01 +10:00
Peter Hutterer
c8483c3a30 Ignore the dispatcher where an interface implementation is missing
This is somewhat superior to just crashing with a SIGSEGV and we have a
valid case for this in libei - when the client switches to the
disconnected state but keeps sending events we just ignore the messages.
2023-03-03 11:27:01 +10:00
Peter Hutterer
1b34bc6f7c test: distinguish better between stderr/stdout of the subprocess 2023-03-03 11:27:01 +10:00
Peter Hutterer
1a64b4963d Check incoming ids for validity
In libei we just check the range is correct.
In libeis we also check that the client is monotonically increasing the
id.
2023-03-03 11:27:01 +10:00
Peter Hutterer
329db61bee eis: remove now-unused macro 2023-03-03 11:27:01 +10:00
Peter Hutterer
2157a9344e brei: use memcpy for the 64bit protocol copy
On some architectures (ARM, afaik) addresses needs to be a multiple
of their word size. Since the protocol doesn't enforce alignment on
multiples of 8, let's use a memcpy to copy any 64-bit number instad of
the pointer access.
2023-03-03 11:27:01 +10:00
Peter Hutterer
086f96a702 proto: split up message length and opcode again
Now that we have 64 bit integers on the wire and 64 bit object IDs,
we're already different to the Wayland protocol. So we might as well get
the full length and split message length and opcode again to make header
parsing and composing simpler.

This effectively reverts commit bf45a7182cb2f4c13f11e141fc846244d3ac6212.
2023-03-03 11:27:01 +10:00
Peter Hutterer
ba51f434a6 proto: switch object ids to 64 bits 2023-03-03 11:27:01 +10:00
Peter Hutterer
d4980d8579 brei: abstract string handling in a struct
Makes the code a bit easier to read and understand than the previous
offset mangling.
2023-03-03 11:27:01 +10:00
Peter Hutterer
d686d4e281 brei: factor out header size for the unit tests 2023-03-03 11:27:01 +10:00
Peter Hutterer
960bb6db26 util: add a strlen0 helper function
Same as strlen() + 1, but handles NULL and avoids typos by forgetting
the +1 in all the sites we need to call it.
2023-03-03 11:27:01 +10:00
Peter Hutterer
0ef1bb95d4 ei: remove obsolete device->id 2023-03-03 11:27:01 +10:00
Peter Hutterer
c998bae33f Remove obsolete declaration 2023-03-03 11:27:01 +10:00
Peter Hutterer
1e0796f432 Remove now-obsolete proto files 2023-03-03 11:27:01 +10:00
Peter Hutterer
b309798bf1 Switch object ids to use the object_id_t typedef 2023-03-03 11:27:01 +10:00
Peter Hutterer
2e1babbb84 test: simplify results handling in the python tests
No point appending the message header components to the results when we
just ignore them later anyway.
2023-03-03 11:27:01 +10:00
Peter Hutterer
8ea6b81f40 Change the ei_device_capability values to match the protocol
In the protocol this is a bitmask, let's make it the same in the
interface to avoid confusion in the implementation.
2023-03-03 11:27:01 +10:00
Peter Hutterer
2338e19aab ei: correct arguments to the invalid object log message 2023-03-03 11:27:01 +10:00
Peter Hutterer
c832ce3ddc protocol: split the handshake version negotiation from the other interfaces
Previously, we'd send one interface_version event for "ei_handshake"
immediately but all others after the client requests handshake.finish.
This was too confusing to document and not clear how it would work, so
let's make this simpler by splitting it up.

There is now a handshake_version event from the server, sent immediately
on connection that denotes the maximum version number for the interface.
And a handshake_version request from the client which must be the first
one by the client.
2023-03-03 11:27:01 +10:00
Peter Hutterer
8b484c8dc2 editorconfig: add XML 2023-03-03 11:27:01 +10:00
Peter Hutterer
5d7f6ab188 protocol: more clarifications 2023-03-03 11:27:01 +10:00
Peter Hutterer
35f5fa102c proto: rename ei_connection_setup to ei_handshake
This is a better name for the initial handshake and easier to
distinguish from the ei_connection this way too.

Suggested by Jonas Ådahl.
2023-03-03 11:27:01 +10:00
Peter Hutterer
f9446e8c02 test: strip all trailing zeroes from the protocol strings
This code worked because the only string we compared against was
"ei_connection_setup" which is 19 actual bytes.
2023-03-03 11:27:01 +10:00
Peter Hutterer
2aaf7acdfc test: fix a ruff warning - f-string without placeholder 2023-03-03 11:27:01 +10:00
Peter Hutterer
705c5d79ac test: remove unused python import 2023-03-03 11:27:01 +10:00
Peter Hutterer
38dc5dc72f proto: shift the capabilities down by one
These were previously (1 << cap) for convenience but that results in the
capability mask on the wire starting at 2 - which is a bit awkward.

Lets shift them down by one so we start the mask at 1.
2023-03-03 11:27:01 +10:00
Peter Hutterer
ae8faa9fbb proto: improve the documentation
After some feedback from Jonas Ådahl and Julan Orth.
2023-03-03 11:27:01 +10:00
Peter Hutterer
11fb722e63 proto: fix wrong references to ei_callback in the pingpong interface 2023-03-03 11:27:01 +10:00
Peter Hutterer
47467bfe0e proto: rename connection_setup.done to .finish
Avoids ambiguity with the .done events from e.g. the seat or the device.
2023-03-03 11:27:01 +10:00
Peter Hutterer
0897722493 proto: drop the seat caps and cross-reference device caps instead 2023-03-03 11:27:01 +10:00
Peter Hutterer
1db37c33d5 scanner: allow for cross-referencing enums
Add another run to the XML parser so we parse enums before Arguments
that cross-reference enums from other interfaces.

This also fixes a type bug - the enum name string was passed to
Argument.create() as Enum and no-one noticed.
2023-03-03 11:27:01 +10:00
Jonas Ådahl
eecf69af48 protocol: Make timestamps a single 64 bit argument
With 64 bit integers on the wire, we don't need to split timestamps in
milliseconds and microsecond parts.
2023-03-03 11:27:01 +10:00
Jonas Ådahl
03c0ab73dd protocol: Add support for 64 bit integers on the wire
This is useful for e.g. not having to split timestamps.
2023-03-03 11:27:01 +10:00