Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove library target #105

Merged
merged 4 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
- name: Test
uses: GabrielBB/xvfb-action@v1
with:
run: cargo test --features=test-ui-replay
run: cargo test

- uses: actions/upload-artifact@v2
with:
Expand Down
8 changes: 0 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,4 @@ ctor = "0.2.8"
[features]
step-decoder = []
record-ui-test = ["serde", "serde_json"]
test-ui-replay = ["serde", "serde_json"]
debug-region-map = []
test-cynthion = []

[[test]]
name = "test_cynthion"
path = "src/test_cynthion.rs"
harness = false
required-features = ["test-cynthion"]
7 changes: 3 additions & 4 deletions src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub struct CaptureWriter {
pub endpoints: DataWriter<Endpoint>,
pub endpoint_states: DataWriter<u8>,
pub endpoint_state_index: CompactWriter<TransferId, Id<u8>>,
#[allow(dead_code)]
pub end_index: CompactWriter<TransferId, TrafficItemId>,
}

Expand All @@ -59,6 +60,7 @@ pub struct CaptureReader {
pub endpoints: DataReader<Endpoint>,
pub endpoint_states: DataReader<u8>,
pub endpoint_state_index: CompactReader<TransferId, Id<u8>>,
#[allow(dead_code)]
pub end_index: CompactReader<TransferId, TrafficItemId>,
}

Expand Down Expand Up @@ -124,6 +126,7 @@ pub fn create_capture()
/// Per-endpoint state shared between readers and writers.
pub struct EndpointShared {
pub total_data: AtomicU64,
#[allow(dead_code)]
pub first_item_id: ArcSwapOption<TrafficItemId>,
}

Expand Down Expand Up @@ -991,10 +994,6 @@ impl CaptureReader {
})
}

pub fn finish(&mut self) {
self.shared.complete.store(true, Release);
}

fn completion(&self) -> CompletionStatus {
use CompletionStatus::*;
match self.shared.complete.load(Acquire) {
Expand Down
23 changes: 0 additions & 23 deletions src/lib.rs

This file was deleted.

53 changes: 43 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,62 @@
// On Windows, produce a GUI app rather than a console one.
#![windows_subsystem = "windows"]

// We need the bitfield macro.
#[macro_use]
extern crate bitfield;

// We need the ctor macro for the replay test on macOS.
#[cfg(all(test, target_os="macos"))]
#[allow(unused_imports)]
#[macro_use]
extern crate ctor;

// Declare all modules used.
mod backend;
mod capture;
mod compact_index;
mod data_stream;
mod decoder;
mod expander;
mod id;
mod index_stream;
mod model;
mod rcu;
mod row_data;
mod stream;
mod test_cynthion;
mod tree_list_model;
mod ui;
mod usb;
mod util;
mod vec_map;

// Declare optional modules.
#[cfg(any(test, feature="record-ui-test"))]
mod record_ui;
#[cfg(test)]
mod test_replay;

use gtk::prelude::*;
use gtk::gio::ApplicationFlags;

use packetry::ui::{
use ui::{
activate,
display_error,
stop_cynthion
};

fn main() {
let application = gtk::Application::new(
Some("com.greatscottgadgets.packetry"),
ApplicationFlags::NON_UNIQUE
);
application.connect_activate(|app| display_error(activate(app)));
application.run_with_args::<&str>(&[]);
display_error(stop_cynthion());
if std::env::args().any(|arg| arg == "--test-cynthion") {
test_cynthion::run_test();
} else {
let application = gtk::Application::new(
Some("com.greatscottgadgets.packetry"),
ApplicationFlags::NON_UNIQUE
);
application.connect_activate(|app| display_error(activate(app)));
application.run_with_args::<&str>(&[]);
display_error(stop_cynthion());
}
}

#[cfg(test)]
mod test_replay;
12 changes: 6 additions & 6 deletions src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

mod imp;

#[cfg(any(feature="test-ui-replay", feature="record-ui-test"))]
#[cfg(any(test, feature="record-ui-test"))]
use {
std::cell::RefCell,
std::rc::Rc,
Expand All @@ -26,7 +26,7 @@ glib::wrapper! {

pub trait GenericModel<Item> where Self: Sized {
fn new(capture: CaptureReader,
#[cfg(any(feature="test-ui-replay", feature="record-ui-test"))]
#[cfg(any(test, feature="record-ui-test"))]
on_item_update: Rc<RefCell<dyn FnMut(u32, String)>>)
-> Result<Self, Error>;
fn set_expanded(&self,
Expand All @@ -41,14 +41,14 @@ pub trait GenericModel<Item> where Self: Sized {

impl GenericModel<TrafficItem> for TrafficModel {
fn new(capture: CaptureReader,
#[cfg(any(feature="test-ui-replay", feature="record-ui-test"))]
#[cfg(any(test, feature="record-ui-test"))]
on_item_update: Rc<RefCell<dyn FnMut(u32, String)>>)
-> Result<Self, Error>
{
let model: TrafficModel = glib::Object::new::<TrafficModel>();
let tree = TreeListModel::new(
capture,
#[cfg(any(feature="test-ui-replay", feature="record-ui-test"))]
#[cfg(any(test, feature="record-ui-test"))]
on_item_update)?;
model.imp().tree.replace(Some(tree));
Ok(model)
Expand Down Expand Up @@ -86,14 +86,14 @@ impl GenericModel<TrafficItem> for TrafficModel {

impl GenericModel<DeviceItem> for DeviceModel {
fn new(capture: CaptureReader,
#[cfg(any(feature="test-ui-replay", feature="record-ui-test"))]
#[cfg(any(test, feature="record-ui-test"))]
on_item_update: Rc<RefCell<dyn FnMut(u32, String)>>)
-> Result<Self, Error>
{
let model: DeviceModel = glib::Object::new::<DeviceModel>();
let tree = TreeListModel::new(
capture,
#[cfg(any(feature="test-ui-replay", feature="record-ui-test"))]
#[cfg(any(test, feature="record-ui-test"))]
on_item_update)?;
model.imp().tree.replace(Some(tree));
Ok(model)
Expand Down
8 changes: 4 additions & 4 deletions src/record_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct Recording {
action_log: File,
#[cfg(feature="record-ui-test")]
output_log: File,
#[cfg(feature="test-ui-replay")]
#[cfg(test)]
output_log: Option<File>,
view_items: HashMap<String, Vec<String>>,
}
Expand All @@ -66,13 +66,13 @@ impl Recording {
.truncate(true)
.open("output.txt")
.expect("Failed to open UI output log file"),
#[cfg(feature="test-ui-replay")]
#[cfg(test)]
output_log: None,
view_items: HashMap::new(),
}
}

#[cfg(feature="test-ui-replay")]
#[cfg(test)]
pub fn set_output(&mut self, file: File) {
self.output_log = Some(file)
}
Expand All @@ -98,7 +98,7 @@ impl Recording {
fn log_output(&mut self, string: String) {
#[cfg(feature="record-ui-test")]
let output_log = &mut self.output_log;
#[cfg(feature="test-ui-replay")]
#[cfg(test)]
let output_log = self.output_log
.as_mut()
.expect("Recording has no output file set");
Expand Down
7 changes: 6 additions & 1 deletion src/row_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
mod imp;

use gtk::glib;
use gtk::prelude::Cast;
use gtk::subclass::prelude::*;

#[cfg(any(test, feature="record-ui-test"))]
use gtk::prelude::Cast;

use crate::capture::{TrafficItem, DeviceItem};
use crate::tree_list_model::ItemNodeRc;

Expand Down Expand Up @@ -52,16 +54,19 @@ impl GenericRowData<DeviceItem> for DeviceRowData {
}

pub trait ToGenericRowData<Item> {
#[cfg(any(test, feature="record-ui-test"))]
fn to_generic_row_data(self) -> Box<dyn GenericRowData<Item>>;
}

impl ToGenericRowData<TrafficItem> for glib::Object {
#[cfg(any(test, feature="record-ui-test"))]
fn to_generic_row_data(self) -> Box<dyn GenericRowData<TrafficItem>> {
Box::new(self.downcast::<TrafficRowData>().unwrap())
}
}

impl ToGenericRowData<DeviceItem> for glib::Object {
#[cfg(any(test, feature="record-ui-test"))]
fn to_generic_row_data(self) -> Box<dyn GenericRowData<DeviceItem>> {
Box::new(self.downcast::<DeviceRowData>().unwrap())
}
Expand Down
8 changes: 4 additions & 4 deletions src/test_cynthion.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use packetry::backend::cynthion::{CynthionDevice, CynthionUsability, Speed};
use packetry::capture::{create_capture, CaptureReader, DeviceId, EndpointId, EndpointTransferId};
use packetry::decoder::Decoder;
use crate::backend::cynthion::{CynthionDevice, CynthionUsability, Speed};
use crate::capture::{create_capture, CaptureReader, DeviceId, EndpointId, EndpointTransferId};
use crate::decoder::Decoder;

use anyhow::{Context, Error};
use futures_lite::future::block_on;
Expand All @@ -9,7 +9,7 @@ use nusb::transfer::RequestBuffer;
use std::thread::sleep;
use std::time::Duration;

fn main() {
pub fn run_test() {
for (speed, ep_addr, length) in [
(Speed::High, 0x81, 4096),
(Speed::Full, 0x82, 512),
Expand Down
10 changes: 5 additions & 5 deletions src/test_replay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use itertools::assert_equal;
use pcap_file::pcap::PcapReader;
use serde_json::Deserializer;

use packetry::decoder::Decoder;
use packetry::model::GenericModel;
use packetry::row_data::{GenericRowData, TrafficRowData, DeviceRowData};
use packetry::record_ui::UiAction;
use packetry::ui::{
use crate::decoder::Decoder;
use crate::model::GenericModel;
use crate::row_data::{GenericRowData, TrafficRowData, DeviceRowData};
use crate::record_ui::UiAction;
use crate::ui::{
UserInterface,
activate,
reset_capture,
Expand Down
8 changes: 4 additions & 4 deletions src/tree_list_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ pub struct TreeListModel<Item, Model, RowData> {
capture: RefCell<CaptureReader>,
root: RootNodeRc<Item>,
regions: RefCell<BTreeMap<u64, Region<Item>>>,
#[cfg(any(feature="test-ui-replay", feature="record-ui-test"))]
#[cfg(any(test, feature="record-ui-test"))]
on_item_update: Rc<RefCell<dyn FnMut(u32, String)>>,
}

Expand All @@ -362,7 +362,7 @@ where Item: 'static + Copy + Debug,
CaptureReader: ItemSource<Item>,
{
pub fn new(mut capture: CaptureReader,
#[cfg(any(feature="test-ui-replay", feature="record-ui-test"))]
#[cfg(any(test, feature="record-ui-test"))]
on_item_update: Rc<RefCell<dyn FnMut(u32, String)>>)
-> Result<Self, Error>
{
Expand All @@ -375,7 +375,7 @@ where Item: 'static + Copy + Debug,
complete: completion.is_complete(),
})),
regions: RefCell::new(BTreeMap::new()),
#[cfg(any(feature="test-ui-replay", feature="record-ui-test"))]
#[cfg(any(test, feature="record-ui-test"))]
on_item_update,
})
}
Expand Down Expand Up @@ -774,7 +774,7 @@ where Item: 'static + Copy + Debug,
if item_updated {
// The node's description may change.
let summary = cap.summary(&item_node.item)?;
#[cfg(any(feature="test-ui-replay", feature="record-ui-test"))]
#[cfg(any(test, feature="record-ui-test"))]
if let Ok(position) = u32::try_from(position) {
let mut on_item_update = self.on_item_update.borrow_mut();
on_item_update(position, summary.clone());
Expand Down
Loading
Loading