Skip to content
Open
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
45 changes: 45 additions & 0 deletions net/cloudflare-speed-cli/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=cloudflare-speed-cli
PKG_VERSION:=1.0.12
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/kavehtehrani/cloudflare-speed-cli/tar.gz/refs/tags/v$(PKG_VERSION)?
PKG_HASH:=4a873aa6fe7fd66ac47df3b0a34038771b4a17b11e0894c69263138fc73208c7

PKG_MAINTAINER:=Dave Marquard <dave@marquard.org>
PKG_LICENSE:=GPL-3.0-only
PKG_LICENSE_FILES:=LICENSE

PKG_BUILD_DEPENDS:=rust/host
PKG_BUILD_PARALLEL:=1

include $(INCLUDE_DIR)/package.mk
include ../../lang/rust/rust-package.mk

# The speed test counts bytes in AtomicU64, which Rust lacks on 32-bit mips,
# powerpc and ARMv5; ring needs SSE2 on 32-bit x86.
define Package/cloudflare-speed-cli
SECTION:=net
CATEGORY:=Network
TITLE:=Cloudflare speed test client with TUI
URL:=https://github.com/kavehtehrani/cloudflare-speed-cli
DEPENDS:=$(RUST_ARCH_DEPENDS) @HAS_ATOMIC64 @!i386
endef

define Package/cloudflare-speed-cli/description
Command line client for speed.cloudflare.com. It measures download
and upload throughput, idle and loaded latency, jitter and packet
loss, and can also run DNS, TLS handshake and traceroute probes.
Results can be shown in an interactive terminal UI or printed as
plain text or JSON.
endef

# The clipboard feature pulls in arboard, which talks to X11 and is of
# no use on a router; keep the TUI but leave the clipboard out.
RUST_PKG_FEATURES:=tui
CARGO_PKG_ARGS+= --no-default-features

$(eval $(call RustBinPackage,cloudflare-speed-cli))
$(eval $(call BuildPackage,cloudflare-speed-cli))
40 changes: 40 additions & 0 deletions net/cloudflare-speed-cli/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/sh
set -e

# Everything here runs without network access, so it works the same in the
# build matrix as on a device.

export HOME=/tmp/cloudflare-speed-cli-test
rm -rf "$HOME"

cloudflare-speed-cli --help | grep -- '--json'

# Pointed at a port nothing listens on, every request fails and the run has
# to come back with a summary once the phase durations are up. This exercises
# the async runtime and the HTTP/UDP clients; a reactor that never delivers
# the connection errors would hang here until the timeout fires.
ARGS="--base-url http://127.0.0.1:1 --download-duration 1s --upload-duration 1s --idle-latency-duration 1s"

rc=0
timeout 60 cloudflare-speed-cli --text $ARGS > "$HOME.out" 2>&1 || rc=$?
if [ "$rc" != 0 ]; then
echo "text run exited with $rc"
cat "$HOME.out"
exit 1
fi
grep '== Summary ==' "$HOME.out"

rc=0
timeout 60 cloudflare-speed-cli --json $ARGS > "$HOME.json" 2> "$HOME.out" || rc=$?
if [ "$rc" != 0 ]; then
echo "json run exited with $rc"
cat "$HOME.out"
exit 1
fi
grep '"base_url": "http://127.0.0.1:1"' "$HOME.json"

# Both runs were auto-saved under $HOME; read them back as history.
cloudflare-speed-cli --export-all-csv "$HOME.csv" 2>&1 | grep 'Exported 2 run(s)'
grep '^timestamp_utc,base_url,' "$HOME.csv"

rm -rf "$HOME" "$HOME.out" "$HOME.json" "$HOME.csv"