Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
reemo3dp committed Jan 24, 2024
1 parent 04a4562 commit 0661ff1
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Test

on:
push:
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup smoke
run: |
curl https://github.com/SamirTalwar/smoke/releases/download/v2.3.2/smoke-v2.3.2-Linux-x86_64 \
-L -o smoke
chmod a+x smoke
- name: Run tests
run: ./smoke .
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
103 changes: 103 additions & 0 deletions klipper_log_tool.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/env bash

set -eo pipefail

HASTEBIN_URL=${HASTEBIN_URL:-https://paste.armbian.com/documents}

usage() {
cat >&2 <<EOF
Usage: $0 [ -u | --upload ] [ -y | --yes ] [ -r | --raw ] [ -a | --all-starts ] [KLIPPER_LOG_FILE]
EOF
exit 1
}

UPLOAD=0
YES=0
RAW=0
ALL_STARTS=0

args=$(getopt -a -o hyura --long help,yes,upload,raw,all-starts -- "$@")
# shellcheck disable=SC2181
if [[ $? -gt 0 ]]; then
usage
fi
eval set -- "${args}"
while :; do
case $1 in
-u | --upload)
UPLOAD=1
shift
;;
-y | --yes)
YES=1
shift
;;
-raw | --raw)
RAW=1
shift
;;
-a | --all-starts)
ALL_STARTS=1
shift
;;
# -- means the end of the arguments; drop this, and break out of the while loop
--)
shift
break
;;
*)
echo >&2 Unsupported option: "$1"
usage
;;
esac
done

if [[ $# -eq 0 ]]; then
FILE="$HOME/printer_data/logs/klippy.log"
if [[ ! -f $FILE ]]; then
echo >&2 "No file specified and default file $FILE does not exist."
usage
fi
fi

set -u

remove_noise() {
grep -vE '^(Stats |Sent |Receive:|Dumping receive queue)'
}

only_last() {
FILE="$1"
sed -z 's/.*Start printer at[^\n]*\n//g' "$FILE"
}

process_klipper_log() {
FILE="$1"
if [[ $RAW -eq 1 ]]; then
cat "$FILE"
return
fi
if [[ $ALL_STARTS -eq 1 ]]; then
remove_noise <"$FILE"
return
fi
only_last "$FILE" |
remove_noise
}

OUTPUT=$(process_klipper_log "$1")
echo "$OUTPUT"

if [[ $UPLOAD -eq 1 ]]; then
if [[ $YES -ne 1 ]]; then
echo "This data will be uploaded to $HASTEBIN_URL for easier sharing. It will be unprotected and publicly available. Type "okay" to continue."
read -r ANSWER
if [[ $ANSWER != "okay" ]]; then
echo "Aborting."
exit 1
fi
fi
RESPONSE=$(echo "$OUTPUT" | curl -sfXPOST -T- "$HASTEBIN_URL")
KEY=$(echo "$RESPONSE" | awk -F '"' '{print $4}')
echo "Pasted to ${HASTEBIN_URL%documents}$KEY"
fi
95 changes: 95 additions & 0 deletions smoke.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
command:
- bash
- klipper_log_tool.sh

tests:
- name: Considers only the last start
args:
- test/only_last_log.txt
stdout: |
===== Config file =====
[virtual_sdcard]
path = /opt/printer_data/gcodes
[pause_resume]
[display_status]
[exclude_object]
[mcu]
serial =
- name: Remove stats, received, sent and dumping messages
args:
- test/remove_noise.txt
stdout: |
Empty otherwise
Dumping serial stats: bytes_write=5424 bytes_read=4673 bytes_retransmit=9 bytes_invalid=0 send_seq=219 receive_seq=219 retransmit_seq=2 srtt=0.001 rttvar=0.001 rto=0.025 ready_bytes=0 upcoming_bytes=0
- name: Should upload to a service
command:
shell:
- bash
script: |
export HASTEBIN_URL=https://httpbin.org/post
./klipper_log_tool.sh test/uploads_to_service.txt -u -y
echo Hi
stdout:
- contains: 'Logline1\nLogline2\nLogline3'
- name: Raw returns everything
args:
- test/raw.txt
- --raw
stdout: |
webhooks client 139646904459424: Disconnected
Restarting printer
Start printer at Sat May 6 16:29:38 2023 (1683390578.7 4387047.6)
===== Config file =====
webhooks client 139646904459424: Disconnected
Restarting printer
Start printer at Sat May 6 16:29:38 2023 (1683390578.7 4387047.6)
===== Config file =====
webhooks client 139646904459424: Disconnected
Receive: 0 151.864215 151.863561 49: seq: 13, identify_response offset=160 data=b'\xf1\xfb\xc7\xf0GF\xeb\xc9t\x92\xd5e\x99V9\xd0\xff}\x92\x16E\x9d\xa5\x9d\xe0\xb5\xcc\x15\xcb\xea\xbe\xea>\xbc\xcb&\xe7\xab)0'
Receive: 1 151.866267 151.865424 49: seq: 14, identify_response offset=200 data=b"\xdbu\xc0%O\xb3'\x06\xa7\xb0\xed\x9d\xc7\xb1\x07\x90\xe7\x16\xa0\xa9\x95\xfe\x91\xd5\x87w=k\xfa\xa2\xe0}C\x08\x8b\x01\xe1K/\xda"
Restarting printer
Start printer at Sat May 6 16:29:38 2023 (1683390578.7 4387047.6)
===== Config file =====
[virtual_sdcard]
path = /opt/printer_data/gcodes
[pause_resume]
[display_status]
[exclude_object]
[mcu]
serial =
- name: All Starts returns starts but no noise
args:
- test/raw.txt
- --all-starts
stdout: |
webhooks client 139646904459424: Disconnected
Restarting printer
Start printer at Sat May 6 16:29:38 2023 (1683390578.7 4387047.6)
===== Config file =====
webhooks client 139646904459424: Disconnected
Restarting printer
Start printer at Sat May 6 16:29:38 2023 (1683390578.7 4387047.6)
===== Config file =====
webhooks client 139646904459424: Disconnected
Restarting printer
Start printer at Sat May 6 16:29:38 2023 (1683390578.7 4387047.6)
===== Config file =====
[virtual_sdcard]
path = /opt/printer_data/gcodes
[pause_resume]
[display_status]
[exclude_object]
[mcu]
serial =
26 changes: 26 additions & 0 deletions test/only_last_log.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Git version: '?'
CPU: 6 core Intel(R) Core(TM) i5-8400T CPU @ 1.70GHz
Python: '2.7.18 (default, Apr 20 2020, 19:34:11) \n[GCC 8.3.0]'
webhooks client 139646904459424: {'program': 'Moonraker', 'version': '?'}
=============== Log rollover at Sat May 6 16:29:26 2023 ===============
mcu 'mcu': Unable to connect
Once the underlying issue is corrected, use the
"FIRMWARE_RESTART" command to reset the firmware, reload the
config, and restart the host software.
Error configuring printer

webhooks client 139646904459424: Disconnected
Restarting printer
Start printer at Sat May 6 16:29:38 2023 (1683390578.7 4387047.6)
===== Config file =====
[virtual_sdcard]
path = /opt/printer_data/gcodes

[pause_resume]

[display_status]

[exclude_object]

[mcu]
serial =
25 changes: 25 additions & 0 deletions test/raw.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
webhooks client 139646904459424: Disconnected
Restarting printer
Start printer at Sat May 6 16:29:38 2023 (1683390578.7 4387047.6)
===== Config file =====
webhooks client 139646904459424: Disconnected
Restarting printer
Start printer at Sat May 6 16:29:38 2023 (1683390578.7 4387047.6)
===== Config file =====
webhooks client 139646904459424: Disconnected
Receive: 0 151.864215 151.863561 49: seq: 13, identify_response offset=160 data=b'\xf1\xfb\xc7\xf0GF\xeb\xc9t\x92\xd5e\x99V9\xd0\xff}\x92\x16E\x9d\xa5\x9d\xe0\xb5\xcc\x15\xcb\xea\xbe\xea>\xbc\xcb&\xe7\xab)0'
Receive: 1 151.866267 151.865424 49: seq: 14, identify_response offset=200 data=b"\xdbu\xc0%O\xb3'\x06\xa7\xb0\xed\x9d\xc7\xb1\x07\x90\xe7\x16\xa0\xa9\x95\xfe\x91\xd5\x87w=k\xfa\xa2\xe0}C\x08\x8b\x01\xe1K/\xda"
Restarting printer
Start printer at Sat May 6 16:29:38 2023 (1683390578.7 4387047.6)
===== Config file =====
[virtual_sdcard]
path = /opt/printer_data/gcodes

[pause_resume]

[display_status]

[exclude_object]

[mcu]
serial =
8 changes: 8 additions & 0 deletions test/remove_noise.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Empty otherwise
Sent 63 160.867442 160.867442 59: seq: 16, i2c_write oid=0 data=b'@\x0e\x00\x07\x0f\t\t\t\r\x05\x00\x06\x0f\t\t\x07\x0f', i2c_write oid=0 data=b'\x00\xb7\x11\x08', i2c_write oid=0 data=b"@\x08\x00\x07\x0f\x08\x08\x07\x0f\x08\x00#'$$4\x1f", i2c_write oid=0 data=b'\x00\xb7\x12\x08'
Sent 64 160.867680 160.867680 48: seq: 17, i2c_write oid=0 data=b'@\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', i2c_write oid=0 data=b'\x00\xb7\x15\x02', i2c_write oid=0 data=b'@\x00\x00\x00\x00', i2c_write oid=0 data=b'\x00\xb7\x15\x06'
Dumping receive queue 100 messages
Receive: 0 151.864215 151.863561 49: seq: 13, identify_response offset=160 data=b'\xf1\xfb\xc7\xf0GF\xeb\xc9t\x92\xd5e\x99V9\xd0\xff}\x92\x16E\x9d\xa5\x9d\xe0\xb5\xcc\x15\xcb\xea\xbe\xea>\xbc\xcb&\xe7\xab)0'
Receive: 1 151.866267 151.865424 49: seq: 14, identify_response offset=200 data=b"\xdbu\xc0%O\xb3'\x06\xa7\xb0\xed\x9d\xc7\xb1\x07\x90\xe7\x16\xa0\xa9\x95\xfe\x91\xd5\x87w=k\xfa\xa2\xe0}C\x08\x8b\x01\xe1K/\xda"
Dumping serial stats: bytes_write=5424 bytes_read=4673 bytes_retransmit=9 bytes_invalid=0 send_seq=219 receive_seq=219 retransmit_seq=2 srtt=0.001 rttvar=0.001 rto=0.025 ready_bytes=0 upcoming_bytes=0
Stats 2685194.7: gcodein=0 mcu: mcu_awake=0.001 mcu_task_avg=0.000009 mcu_task_stddev=0.000007 bytes_write=10215 bytes_read=83410 bytes_retransmit=9 bytes_invalid=0 send_seq=986 receive_seq=986 retransmit_seq=2 srtt=0.003 rttvar=0.000 rto=0.025 ready_bytes=0 stalled_bytes=0 freq=72004636 heater_bed: target=0 temp=20.0 pwm=0.000 sysload=0.06 cputime=9.245 memavail=5435296 print_time=1247.129 buffer_time=0.000 print_stall=0 extruder: target=0 temp=20.7 pwm=0.000
3 changes: 3 additions & 0 deletions test/uploads_to_service.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Logline1
Logline2
Logline3

0 comments on commit 0661ff1

Please sign in to comment.